]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - tests/lib.sh.test
3568c47de354f64e4dbfebd24fcf7ead4ee1ecb5
[config/dotfiles.git] / tests / lib.sh.test
1 # Tests for lib.sh.
2
3
4 . ../lib.sh
5
6 # which with proper exit codes and output to stdout.
7 which() {
8     if [ $1 = ls ]; then
9         echo /bin/ls
10     else
11         echo no doesnt-exist in /usr/bin /bin /usr/sbin /sbin
12         return 1
13     fi
14 }
15 echo stdout which
16 installed ls && echo ls installed
17 installed doesnt-exist && echo doesnt-exist installed
18
19 # which with proper exit codes and output to stderr in case of an error.
20 which() {
21     if [ $1 = ls ]; then
22         echo /bin/ls
23     else
24         echo no doesnt-exist in /usr/bin /bin /usr/sbin /sbin >&2
25         return 1
26     fi
27 }
28 echo stderr which
29 installed ls && echo ls installed
30 installed doesnt-exist && echo doesnt-exist installed
31
32 # which with no proper exit codes and output to stdout in case of an error.
33 which() {
34     if [ $1 = ls ]; then
35         echo /bin/ls
36     else
37         echo no doesnt-exist in /usr/bin /bin /usr/sbin /sbin
38     fi
39 }
40 echo stupid which
41 installed ls && echo ls installed
42 installed doesnt-exist && echo doesnt-exist installed
43
44 # which with proper exit codes and no output in case of an error.
45 which() {
46     if [ $1 = ls ]; then
47         echo /bin/ls
48     else
49         return 1
50     fi
51 }
52 echo different which
53 installed ls && echo ls installed
54 installed doesnt-exist && echo doesnt-exist installed
55
56
57 # Tests for generate().
58 echo "Simple test file for generate() using m4.
59 include(../lib.m4)dnl
60 IF(TEST,m4)
61     m4
62 FI
63 IF(TEST,n4)
64     n4
65 FI" > tmp/test.m4
66 generate m4 tmp/test -DTEST=m4
67 # Remove the line with the current date as it changes every time.
68 cat tmp/test | grep -v "It was generated from tmp/test.m4"
69
70 # Test multiple arguments to generate().
71 echo "Test with multiple arguments passed to generate().
72 first: FIRST
73 second: SECOND
74 " > tmp/test-multiple.m4
75 generate m4 tmp/test-multiple -DFIRST=first -DSECOND=second
76 # Remove the line with the current date as it changes every time.
77 cat tmp/test-multiple | grep -v "It was generated from tmp/test-multiple.m4"
78
79 # Test multiple arguments with spaces to generate().
80 echo "Test with multiple arguments with spaces passed to generate().
81 first: FIRST
82 second: SECOND
83 " > tmp/test-multiple-spaces.m4
84 generate m4 tmp/test-multiple-spaces -DFIRST="first with spaces" \
85                                      -DSECOND="second with spaces"
86 # Remove the line with the current date as it changes every time.
87 cat tmp/test-multiple-spaces \
88     | grep -v "It was generated from tmp/test-multiple-spaces.m4"
89
90 # Test generate() using awk.
91 echo "Simple test fiel for generate() using awk.
92 first second
93 " > tmp/test-awk.in
94 generate awk tmp/test-awk '{ print $1 }'
95 # Remove the line with the current date as it changes every time.
96 cat tmp/test-awk | grep -v "It was generated from tmp/test-awk.in"
97
98 # Test generate() using perl.
99 echo "Simple test fiel for generate() using perl.
100 first second
101 " > tmp/test-perl.in
102 generate perl tmp/test-perl -p -e 's/first/best/'
103 # Remove the line with the current date as it changes every time.
104 cat tmp/test-perl | grep -v "It was generated from tmp/test-perl.in"
105
106 # Test generate() using cat.
107 echo "Simple test fiel for generate() using cat (simple copy).
108
109 ...
110 " > tmp/test-cat.real
111 generate cat tmp/test-cat .real
112 # Remove the line with the current date as it changes every time.
113 cat tmp/test-cat | grep -v "It was generated from tmp/test-cat.real"
114
115 # vim: ft=sh