1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Test case for OSH readlink.
|
4 | #
|
5 | # Note: there is also a demo to run like this:
|
6 | #
|
7 | # $ demo/readlink-demo.sh all
|
8 | #
|
9 | # Usage:
|
10 | # gold/readlink.sh <function name>
|
11 |
|
12 | set -o nounset
|
13 | set -o pipefail
|
14 | #set -o errexit
|
15 |
|
16 | test-readlink() {
|
17 | readlink -f _tmp/gold-bin/readlink
|
18 | echo $?
|
19 |
|
20 | readlink -f libc.so
|
21 | echo $?
|
22 |
|
23 | # busybox 1.35.0 changed behavior here! It now matches GNU readlink.
|
24 | readlink -f /nonexistent
|
25 | echo $?
|
26 |
|
27 | readlink -f /nonexistent/foo
|
28 | echo $?
|
29 |
|
30 | return
|
31 |
|
32 | # NOTE: busybox doesn't accept multiple arguments.
|
33 | echo 'Multiple arguments with an error in the middle'
|
34 | readlink -f _tmp/gold-bin/readlink /nonexistent/foo libc.so
|
35 | echo $?
|
36 | }
|
37 |
|
38 | # For this readlink gold test, we need a custom test driver.
|
39 | compare() {
|
40 | mkdir -p _tmp/gold-bin
|
41 | ln -s -f -v $PWD/../oil_DEPS/spec-bin/busybox _tmp/gold-bin/readlink
|
42 |
|
43 | if ! _tmp/gold-bin/readlink --help; then
|
44 | echo "busybox readlink not working"
|
45 | fi
|
46 |
|
47 | # Use the readlink in busybox.
|
48 | PATH="_tmp/gold-bin:$PATH" $0 test-readlink > _tmp/busybox-readlink.txt
|
49 |
|
50 | # Use the readlink in OSH.
|
51 | PATH="bin/:$PATH" $0 test-readlink > _tmp/osh-readlink.txt
|
52 |
|
53 | if diff -u _tmp/{busybox,osh}-readlink.txt; then
|
54 | echo PASS
|
55 | else
|
56 | echo FAIL
|
57 | return 1
|
58 | fi
|
59 | }
|
60 |
|
61 | "$@"
|