r27: added two functions
[carnet-tools-cn.git] / test / Makefile
1 # -*- Makefile -*-
2 # for cp-update tests
3
4 # Created by: ddzeko@srce.hr, 2005-03-20
5
6 # path to cp-update script
7 CPUPDATE=../cp-update.new
8
9 tests: test0 test1 test2 test3 test4 test5 test6
10         @echo "All tests completed successfully"
11         @cp test-file.start test-file
12         
13 clean: test0 test-file.start
14         rm -f test[0-9] test[0-9][0-9] test-file.[0-9]*
15
16 # prepare everything for test sequence
17 test0: test-file.start
18         cmp test-file test-file.start >/dev/null 2>&1 || cp test-file.start test-file
19
20 # test line matching
21 # - should match only from the beginning of line
22 #   not in the middle of it, so this text should
23 #   be added to the end of the file, also adding
24 #   newline to it (it's missing from the test-file)     
25 test1:
26         echo Block inserted by $@ | $(CPUPDATE) -i update $@ test-file
27         cp test-file test-new
28         cmp test-new $@.ok
29         mv test-new $@
30         echo Succeeded $@
31
32 # test placement
33 # - insert something on top of the file 
34 test2:
35         echo Block inserted by $@ | $(CPUPDATE) -t $@ test-file
36         cp test-file test-new
37         cmp test-new $@.ok
38         mv test-new $@
39         echo Succeeded $@
40
41 # test placement
42 # - insert something right in the middle using --insert-after
43 test3:
44         echo Block inserted by $@ | $(CPUPDATE) --insert-after '</apache>' $@ test-file
45         cp test-file test-new
46         cmp test-new $@.ok
47         mv test-new $@
48         echo Succeeded $@
49
50 # insert something at the end using --insert-after, due to
51 #   failed match -- implicit placement at the end is used
52 test4:
53         echo Block inserted by $@ | $(CPUPDATE) --insert-after 'abracadabra' $@ test-file
54         cp test-file test-new
55         cmp test-new $@.ok
56         mv test-new $@
57         echo Succeeded $@
58
59 # insert bigger blocks we can
60 # - also, using regexp match
61 # - also, alternative comment character 
62 # - won't work with old cp-update (no -R)
63 test5:
64         perl -e 'print "test line $$_ by $$ARGV[0]\n" for 1..5;' $@ \
65                  | $(CPUPDATE) -R -c ';' --insert-after '[Jj]aneiro' $@ test-file
66         cp test-file test-new
67         cmp test-new $@.ok
68         mv test-new $@
69         echo Succeeded $@
70
71 # now remove everything
72 test6: test1 test2 test3 test4 test5
73         for i in test[1-4]; do $(CPUPDATE) -r $$i test-file; done
74         $(CPUPDATE) -r -c ';' test5 test-file
75         cp test-file.start $@.ok
76         echo >> $@.ok
77         cmp test-file $@.ok
78         cp test-file $@
79         echo Succeeded $@
80
81 # more tests needed
82 # --insert-before
83 # --begin/end marks
84 # --in-place mode
85 # --no-close mode
86
87 # more test on development roadmap:
88 # -- add file-locking - test concurrent updates
89         
90 .SILENT:
91 .PHONY: tests test0 clean