]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - tests/lib.sh.test
lib.sh: Fix m4() to work with arguments with spaces.
[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 m4().
26 echo "Simple test file for m4.
27 IF(TEST,m4)
28     m4
29 FI
30 IF(TEST,n4)
31     n4
32 FI" > tmp/test.m4
33 m4 tmp/test -DTEST=m4
34 # Remove the line with the current date as it changes every time.
35 cat tmp/test | grep -v "It was generated from tmp/test.m4"
36
37 # Test multiple arguments to m4().
38 echo "Test with multiple arguments passed to m4.
39 first: FIRST
40 second: SECOND
41 " > tmp/test-multiple.m4
42 m4 tmp/test-multiple -DFIRST=first -DSECOND=second
43 # Remove the line with the current date as it changes every time.
44 cat tmp/test-multiple | grep -v "It was generated from tmp/test-multiple.m4"
45
46 # Test multiple arguments with spaces to m4().
47 echo "Test with multiple arguments with spaces passed to m4.
48 first: FIRST
49 second: SECOND
50 " > tmp/test-multiple-spaces.m4
51 m4 tmp/test-multiple-spaces -DFIRST="first with spaces" \
52                             -DSECOND="second with spaces"
53 # Remove the line with the current date as it changes every time.
54 cat tmp/test-multiple-spaces \
55     | grep -v "It was generated from tmp/test-multiple-spaces.m4"
56
57 # vim: ft=sh