r90: Dodan --change u cp-update
[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
8
9 tests: test0 test1 test2 test3 test4 test5 test6 test7 test8
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][a-zA-Z0-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 # change/replace existing blocks
72 # - even if they do not previously exist (fall-back to insert)
73 test6:
74         perl -e 'print "test line $$_ by $$ARGV[0]\n" for 14..18;' testChange \
75                  | $(CPUPDATE) -x -i 'something' testChange test-file
76         cp test-file test-new
77         cmp test-new $@.ok
78         mv test-new $@
79         echo Succeeded $@
80
81 # change/replace existing blocks
82 # - just change it Sam
83 test7: test6
84         cp test6 test6c
85         perl -e 'print "test line $$_ by $$ARGV[0]\n" for 22..26;' testChange \
86                  | $(CPUPDATE) -x -i 'something' testChange test6c
87         cp test6c test-new
88         cmp test-new $@.ok
89         mv test-new $@
90         echo Succeeded $@
91
92 # now remove everything
93 test8: test1 test2 test3 test4 test5 test6
94         for i in test[1-4] testChange; do $(CPUPDATE) -r $$i test-file; done
95         $(CPUPDATE) -r -c ';' test5 test-file
96         cp test-file.start $@.ok
97         echo >> $@.ok
98         cmp test-file $@.ok
99         cp test-file $@
100         echo Succeeded $@
101
102 # more tests needed
103 # --insert-before
104 # --begin/end marks
105 # --in-place mode
106 # --no-close mode
107
108 # more test on development roadmap:
109 # -- add file-locking - test concurrent updates
110         
111 .SILENT:
112 .PHONY: tests test0 clean