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__"
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons(match=TestCmd.match_re)
38 # Run all of the tests with both types of source signature
39 # to make sure there's no difference in behavior.
40 for source_signature in ['MD5', 'timestamp']:
42 print "Testing Value node with source signatures:", source_signature
44 test.write('SConstruct', """
45 SourceSignatures(r'%(source_signature)s')
48 def __init__(self, value): self.value = value
49 def __str__(self): return "C=" + str(self.value)
51 P = ARGUMENTS.get('prefix', '/usr/local')
55 def create(target, source, env):
56 open(str(target[0]), 'wb').write(source[0].get_contents())
59 env['BUILDERS']['B'] = Builder(action = create)
60 env['BUILDERS']['S'] = Builder(action = '%(_python_)s put $SOURCES into $TARGET')
61 env.B('f1.out', Value(P))
62 env.B('f2.out', env.Value(L))
63 env.B('f3.out', Value(C))
64 env.S('f4.out', Value(L))
66 def create_value (target, source, env):
67 target[0].write(source[0].get_contents ())
69 def create_value_file (target, source, env):
70 open(str(target[0]), 'wb').write(source[0].read())
72 env['BUILDERS']['B2'] = Builder(action = create_value)
73 env['BUILDERS']['B3'] = Builder(action = create_value_file)
84 open(sys.argv[-1],'wb').write(string.join(sys.argv[1:-2]))
87 test.run(arguments='-c')
90 out7 = """create_value(["'my value'"], ["f3.out"])"""
91 out8 = """create_value_file(["f5.out"], ["'my value'"])"""
93 out1 = """create(["f1.out"], ["'/usr/local'"])"""
94 out2 = """create(["f2.out"], ["10"])"""
95 out3 = """create\\(\\["f3.out"\\], \\["<.*.Custom instance at """
96 #" <- unconfuses emacs syntax highlighting
98 test.fail_test(string.find(test.stdout(), out1) == -1)
99 test.fail_test(string.find(test.stdout(), out2) == -1)
100 test.fail_test(string.find(test.stdout(), out7) == -1)
101 test.fail_test(string.find(test.stdout(), out8) == -1)
102 test.fail_test(re.search(out3, test.stdout()) == None)
104 test.must_match('f1.out', "/usr/local")
105 test.must_match('f2.out', "10")
106 test.must_match('f3.out', "C=/usr/local")
107 test.must_match('f4.out', '10')
108 test.must_match('f5.out', "C=/usr/local")
110 test.up_to_date(arguments='.')
112 test.run(arguments='prefix=/usr')
113 out4 = """create(["f1.out"], ["'/usr'"])"""
114 out5 = """create(["f2.out"], ["4"])"""
115 out6 = """create\\(\\["f3.out"\\], \\["<.*.Custom instance at """
116 #" <- unconfuses emacs syntax highlighting
117 test.fail_test(string.find(test.stdout(), out4) == -1)
118 test.fail_test(string.find(test.stdout(), out5) == -1)
119 test.fail_test(re.search(out6, test.stdout()) == 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('prefix=/usr', '.')
128 test.unlink('f3.out')
130 test.run(arguments='prefix=/var')
131 out4 = """create(["f1.out"], ["'/var'"])"""
133 test.fail_test(string.find(test.stdout(), out4) == -1)
134 test.fail_test(string.find(test.stdout(), out5) != -1)
135 test.fail_test(string.find(test.stdout(), out7) == -1)
136 test.fail_test(string.find(test.stdout(), out8) == -1)
137 test.fail_test(re.search(out6, test.stdout()) == None)
139 test.up_to_date('prefix=/var', '.')
141 test.must_match('f1.out', "/var")
142 test.must_match('f2.out', "4")
143 test.must_match('f3.out', "C=/var")
144 test.must_match('f4.out', "4")
145 test.must_match('f5.out', "C=/var")