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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
32 _python_ = TestSCons._python_
34 test = TestSCons.TestSCons(match=TestCmd.match_re)
36 python = TestSCons.python
38 SConstruct_content = """
39 Decider(r'%(source_signature)s')
42 def __init__(self, value): self.value = value
43 def __str__(self): return "C=" + str(self.value)
45 P = ARGUMENTS.get('prefix', '/usr/local')
49 def create(target, source, env):
50 open(str(target[0]), 'wb').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 open(str(target[0]), 'wb').write(source[0].read())
66 env['BUILDERS']['B2'] = Builder(action = create_value)
67 env['BUILDERS']['B3'] = Builder(action = create_value_file)
74 test.write('put.py', """\
77 open(sys.argv[-1],'wb').write(" ".join(sys.argv[1:-2]))
80 # Run all of the tests with both types of source signature
81 # to make sure there's no difference in behavior.
82 for source_signature in ['MD5', 'timestamp-newer']:
84 print "Testing Value node with source signatures:", source_signature
86 test.write('SConstruct', SConstruct_content % locals())
88 test.run(arguments='-c')
91 out7 = """create_value(['my value'], ["f3.out"])"""
92 out8 = """create_value_file(["f5.out"], ['my value'])"""
94 out1 = """create(["f1.out"], ['/usr/local'])"""
95 out2 = """create(["f2.out"], [10])"""
96 out3 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
97 #" <- unconfuses emacs syntax highlighting
99 test.must_contain_all_lines(test.stdout(), [out1, out2, out7, out8])
100 test.fail_test(re.search(out3, test.stdout()) == None)
102 test.must_match('f1.out', "/usr/local")
103 test.must_match('f2.out', "10")
104 test.must_match('f3.out', "C=/usr/local")
105 test.must_match('f4.out', '10')
106 test.must_match('f5.out', "C=/usr/local")
108 test.up_to_date(arguments='.')
110 test.run(arguments='prefix=/usr')
111 out4 = """create(["f1.out"], ['/usr'])"""
112 out5 = """create(["f2.out"], [4])"""
113 out6 = """create\\(\\["f3.out"\\], \\[<.*.Custom instance at """
114 #" <- unconfuses emacs syntax highlighting
115 test.must_contain_all_lines(test.stdout(), [out4, out5])
116 test.fail_test(re.search(out6, test.stdout()) == None)
118 test.must_match('f1.out', "/usr")
119 test.must_match('f2.out', "4")
120 test.must_match('f3.out', "C=/usr")
121 test.must_match('f4.out', '4')
123 test.up_to_date('prefix=/usr', '.')
125 test.unlink('f3.out')
127 test.run(arguments='prefix=/var')
128 out4 = """create(["f1.out"], ['/var'])"""
130 test.must_contain_all_lines(test.stdout(), [out4, out7, out8])
131 test.must_not_contain_any_line(test.stdout(), [out5])
132 test.fail_test(re.search(out6, test.stdout()) == None)
134 test.up_to_date('prefix=/var', '.')
136 test.must_match('f1.out', "/var")
137 test.must_match('f2.out', "4")
138 test.must_match('f3.out', "C=/var")
139 test.must_match('f4.out', "4")
140 test.must_match('f5.out', "C=/var")
146 # indent-tabs-mode:nil
148 # vim: set expandtab tabstop=4 shiftwidth=4: