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