Use python1.5 in default Aegis builds. Fix testing infrastructure for Python 1.5.
[scons.git] / test / SConsignFile.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import TestSCons
28 import os.path
29
30 python = TestSCons.python
31
32 test = TestSCons.TestSCons()
33
34 test.subdir('work1', ['work1', 'subdir'])
35 test.subdir('work2', ['work2', 'subdir'])
36
37 test.write('build.py', r"""
38 import sys
39 contents = open(sys.argv[2], 'rb').read()
40 file = open(sys.argv[1], 'wb')
41 file.write(contents)
42 file.close()
43 """)
44
45 #
46 test.write(['work1', 'SConstruct'], """
47 SConsignFile()
48 B = Builder(action = "%s ../build.py $TARGETS $SOURCES")
49 env = Environment(BUILDERS = { 'B' : B })
50 env.B(target = 'f1.out', source = 'f1.in')
51 env.B(target = 'f2.out', source = 'f2.in')
52 env.B(target = 'subdir/f3.out', source = 'subdir/f3.in')
53 env.B(target = 'subdir/f4.out', source = 'subdir/f4.in')
54 """ % python)
55
56 test.write(['work1', 'f1.in'], "work1/f1.in\n")
57 test.write(['work1', 'f2.in'], "work1/f2.in\n")
58 test.write(['work1', 'subdir', 'f3.in'], "work1/subdir/f3.in\n")
59 test.write(['work1', 'subdir', 'f4.in'], "work1/subdir/f4.in\n")
60
61 test.run(chdir = 'work1')
62
63 def any_dbm_file(prefix):
64     return os.path.exists(prefix) \
65            or os.path.exists(prefix + '.dat') \
66            or os.path.exists(prefix + '.dir')
67
68 test.fail_test(not any_dbm_file(test.workpath('work1', '.sconsign.dbm')))
69 test.must_not_exist(test.workpath('work1', '.sconsign'))
70 test.must_not_exist(test.workpath('work1', 'subdir', '.sconsign'))
71   
72 test.must_match(['work1', 'f1.out'], "work1/f1.in\n")
73 test.must_match(['work1', 'f2.out'], "work1/f2.in\n")
74 test.must_match(['work1', 'subdir', 'f3.out'], "work1/subdir/f3.in\n")
75 test.must_match(['work1', 'subdir', 'f4.out'], "work1/subdir/f4.in\n")
76
77 test.up_to_date(chdir = 'work1', arguments = '.')
78
79 test.fail_test(not any_dbm_file(test.workpath('work1', '.sconsign.dbm')))
80 test.must_not_exist(test.workpath('work1', '.sconsign'))
81 test.must_not_exist(test.workpath('work1', 'subdir', '.sconsign'))
82
83 #
84 test.write(['work2', 'SConstruct'], """
85 e = Environment(XXX = 'scons')
86 e.SConsignFile('my_${XXX}ign')
87 B = Builder(action = "%s ../build.py $TARGETS $SOURCES")
88 env = Environment(BUILDERS = { 'B' : B })
89 env.B(target = 'f5.out', source = 'f5.in')
90 env.B(target = 'f6.out', source = 'f6.in')
91 env.B(target = 'subdir/f7.out', source = 'subdir/f7.in')
92 env.B(target = 'subdir/f8.out', source = 'subdir/f8.in')
93 """ % python)
94
95 test.write(['work2', 'f5.in'], "work2/f5.in\n")
96 test.write(['work2', 'f6.in'], "work2/f6.in\n")
97 test.write(['work2', 'subdir', 'f7.in'], "work2/subdir/f7.in\n")
98 test.write(['work2', 'subdir', 'f8.in'], "work2/subdir/f8.in\n")
99
100 test.run(chdir = 'work2')
101
102 test.fail_test(not any_dbm_file(test.workpath('work2', 'my_sconsign')))
103 test.fail_test(any_dbm_file(test.workpath('work2', '.sconsign.dbm')))
104 test.must_not_exist(test.workpath('work2', '.sconsign'))
105 test.must_not_exist(test.workpath('work2', 'subdir', '.sconsign'))
106
107 test.must_match(['work2', 'f5.out'], "work2/f5.in\n")
108 test.must_match(['work2', 'f6.out'], "work2/f6.in\n")
109 test.must_match(['work2', 'subdir', 'f7.out'], "work2/subdir/f7.in\n")
110 test.must_match(['work2', 'subdir', 'f8.out'], "work2/subdir/f8.in\n")
111
112 test.up_to_date(chdir = 'work2', arguments = '.')
113
114 test.fail_test(not any_dbm_file(test.workpath('work2', 'my_sconsign')))
115 test.fail_test(any_dbm_file(test.workpath('work2', '.sconsign.dbm')))
116 test.must_not_exist(test.workpath('work2', '.sconsign'))
117 test.must_not_exist(test.workpath('work2', 'subdir', '.sconsign'))
118
119 test.pass_test()