]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - tests/lib.sh.test
lib.sh: Improve installed() to work with more which.
[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         (exit 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         (exit 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
45 # Tests for generate().
46 echo "Simple test file for generate() using m4.
47 include(../lib.m4)dnl
48 IF(TEST,m4)
49     m4
50 FI
51 IF(TEST,n4)
52     n4
53 FI" > tmp/test.m4
54 generate m4 tmp/test -DTEST=m4
55 # Remove the line with the current date as it changes every time.
56 cat tmp/test | grep -v "It was generated from tmp/test.m4"
57
58 # Test multiple arguments to generate().
59 echo "Test with multiple arguments passed to generate().
60 first: FIRST
61 second: SECOND
62 " > tmp/test-multiple.m4
63 generate m4 tmp/test-multiple -DFIRST=first -DSECOND=second
64 # Remove the line with the current date as it changes every time.
65 cat tmp/test-multiple | grep -v "It was generated from tmp/test-multiple.m4"
66
67 # Test multiple arguments with spaces to generate().
68 echo "Test with multiple arguments with spaces passed to generate().
69 first: FIRST
70 second: SECOND
71 " > tmp/test-multiple-spaces.m4
72 generate m4 tmp/test-multiple-spaces -DFIRST="first with spaces" \
73                                      -DSECOND="second with spaces"
74 # Remove the line with the current date as it changes every time.
75 cat tmp/test-multiple-spaces \
76     | grep -v "It was generated from tmp/test-multiple-spaces.m4"
77
78 # Test generate() using awk.
79 echo "Simple test fiel for generate() using awk.
80 first second
81 " > tmp/test-awk.in
82 generate awk tmp/test-awk '{ print $1 }'
83 # Remove the line with the current date as it changes every time.
84 cat tmp/test-awk | grep -v "It was generated from tmp/test-awk.in"
85
86 # Test generate() using perl.
87 echo "Simple test fiel for generate() using perl.
88 first second
89 " > tmp/test-perl.in
90 generate perl tmp/test-perl -p -e 's/first/best/'
91 # Remove the line with the current date as it changes every time.
92 cat tmp/test-perl | grep -v "It was generated from tmp/test-perl.in"
93
94 # Test generate() using cat.
95 echo "Simple test fiel for generate() using cat (simple copy).
96
97 ...
98 " > tmp/test-cat.real
99 generate cat tmp/test-cat .real
100 # Remove the line with the current date as it changes every time.
101 cat tmp/test-cat | grep -v "It was generated from tmp/test-cat.real"
102
103 # vim: ft=sh