]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - tests/lib.sh.test
lib.sh: Add generate() which replaces m4().
[config/dotfiles.git] / tests / lib.sh.test
1 # Tests for lib.sh.
2
3
4 . ../lib.sh
5
6 # Tests for installed() with hopefully proper exit codes (1 if the program was
7 # not found).
8 installed ls && echo ls installed
9 installed doesnt-exist && echo doesnt-exist installed
10
11 # Simulate BSD `which` like on Mac OS X which doesn't use exit codes.
12 function which() {
13     echo Mac OS X which for $1 >&2
14     if [ $1 = ls ]; then
15         echo /bin/ls
16     else
17         echo no doesnt-exist in /usr/bin /bin /usr/sbin /sbin
18     fi
19 }
20 # Tests for installed() without exit codes.
21 installed ls && echo ls installed
22 installed doesnt-exist && echo doesnt-exist installed
23
24
25 # Tests for generate().
26 echo "Simple test file for generate() using m4.
27 include(../lib.m4)dnl
28 IF(TEST,m4)
29     m4
30 FI
31 IF(TEST,n4)
32     n4
33 FI" > tmp/test.m4
34 generate m4 tmp/test -DTEST=m4
35 # Remove the line with the current date as it changes every time.
36 cat tmp/test | grep -v "It was generated from tmp/test.m4"
37
38 # Test multiple arguments to generate().
39 echo "Test with multiple arguments passed to generate().
40 first: FIRST
41 second: SECOND
42 " > tmp/test-multiple.m4
43 generate m4 tmp/test-multiple -DFIRST=first -DSECOND=second
44 # Remove the line with the current date as it changes every time.
45 cat tmp/test-multiple | grep -v "It was generated from tmp/test-multiple.m4"
46
47 # Test multiple arguments with spaces to generate().
48 echo "Test with multiple arguments with spaces passed to generate().
49 first: FIRST
50 second: SECOND
51 " > tmp/test-multiple-spaces.m4
52 generate m4 tmp/test-multiple-spaces -DFIRST="first with spaces" \
53                                      -DSECOND="second with spaces"
54 # Remove the line with the current date as it changes every time.
55 cat tmp/test-multiple-spaces \
56     | grep -v "It was generated from tmp/test-multiple-spaces.m4"
57
58 # Test generate() using awk.
59 echo "Simple test fiel for generate() using awk.
60 first second
61 " > tmp/test-awk.in
62 generate awk tmp/test-awk '{ print $1 }'
63 # Remove the line with the current date as it changes every time.
64 cat tmp/test-awk | grep -v "It was generated from tmp/test-awk.in"
65
66 # Test generate() using cat.
67 echo "Simple test fiel for generate() using cat (simple copy).
68
69 ...
70 " > tmp/test-cat.real
71 generate cat tmp/test-cat .real
72 # Remove the line with the current date as it changes every time.
73 cat tmp/test-cat | grep -v "It was generated from tmp/test-cat.real"
74
75 # vim: ft=sh