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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
24 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31 _python_
= TestSCons
._python
_
33 test
= TestSCons
.TestSCons(match
=TestCmd
.match_re
)
35 python
= TestSCons
.python
37 SConstruct_content
= """
38 Decider(r'%(source_signature)s')
41 def __init__(self, value): self.value = value
42 def __str__(self): return "C=" + str(self.value)
44 P = ARGUMENTS.get('prefix', '/usr/local')
48 def create(target, source, env):
49 with open(str(target[0]), 'wb') as f:
50 f.write(source[0].get_contents())
53 env['BUILDERS']['B'] = Builder(action = create)
54 env['BUILDERS']['S'] = Builder(action = r'%(_python_)s put.py $SOURCES into $TARGET')
55 env.B('f1.out', Value(P))
56 env.B('f2.out', env.Value(L))
57 env.B('f3.out', Value(C))
58 env.S('f4.out', Value(L))
60 def create_value (target, source, env):
61 target[0].write(source[0].get_contents())
63 def create_value_file (target, source, env):
64 with open(str(target[0]), 'wb') as f:
65 f.write(source[0].read())
67 env['BUILDERS']['B2'] = Builder(action = create_value)
68 env['BUILDERS']['B3'] = Builder(action = create_value_file)
75 test
.write('put.py', """\
78 with open(sys.argv[-1],'w') as f:
79 f.write(" ".join(sys.argv[1:-2]))
82 # Run all of the tests with both types of source signature
83 # to make sure there's no difference in behavior.
84 for source_signature
in ['MD5', 'timestamp-newer']:
86 print("Testing Value node with source signatures:", source_signature
)
88 test
.write('SConstruct', SConstruct_content
% locals())
90 test
.run(arguments
='-c')
93 out7
= """create_value(['my value'], ["f3.out"])"""
94 out8
= """create_value_file(["f5.out"], ['my value'])"""
96 out1
= """create(["f1.out"], ['/usr/local'])"""
97 out2
= """create(["f2.out"], [10])"""
98 out3
= """create\\(\\["f3.out"\\], \\[<.*.Custom (instance|object) at """
99 #" <- unconfuses emacs syntax highlighting
101 test
.must_contain_all_lines(test
.stdout(), [out1
, out2
, out7
, out8
])
103 test
.fail_test(re
.search(out3
, test
.stdout()) is None)
105 test
.must_match('f1.out', "/usr/local")
106 test
.must_match('f2.out', "10")
107 test
.must_match('f3.out', "C=/usr/local")
108 test
.must_match('f4.out', '10')
109 test
.must_match('f5.out', "C=/usr/local")
111 test
.up_to_date(arguments
='.')
113 test
.run(options
='prefix=/usr')
114 out4
= """create(["f1.out"], ['/usr'])"""
115 out5
= """create(["f2.out"], [4])"""
116 out6
= """create\\(\\["f3.out"\\], \\[<.*.Custom (instance|object) at """
117 #" <- unconfuses emacs syntax highlighting
118 test
.must_contain_all_lines(test
.stdout(), [out4
, out5
])
119 test
.fail_test(re
.search(out6
, test
.stdout()) is None)
121 test
.must_match('f1.out', "/usr")
122 test
.must_match('f2.out', "4")
123 test
.must_match('f3.out', "C=/usr")
124 test
.must_match('f4.out', '4')
126 test
.up_to_date(options
='prefix=/usr', arguments
='.')
128 test
.unlink('f3.out')
130 test
.run(options
='prefix=/var')
131 out4
= """create(["f1.out"], ['/var'])"""
133 test
.must_contain_all_lines(test
.stdout(), [out4
, out7
, out8
])
134 test
.must_not_contain_any_line(test
.stdout(), [out5
])
135 test
.fail_test(re
.search(out6
, test
.stdout()) is None)
137 test
.up_to_date(options
='prefix=/var', arguments
='.')
139 test
.must_match('f1.out', "/var")
140 test
.must_match('f2.out', "4")
141 test
.must_match('f3.out', "C=/var")
142 test
.must_match('f4.out', "4")
143 test
.must_match('f5.out', "C=/var")
149 # indent-tabs-mode:nil
151 # vim: set expandtab tabstop=4 shiftwidth=4: