5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 This test tests directories as source files. The correct behavior is that
28 any file under a directory acts like a source file of that directory.
29 In other words, if a build has a directory as a source file, any
30 change in any file under that directory should trigger a rebuild.
36 test
= TestSCons
.TestSCons()
38 test
.subdir('tstamp', [ 'tstamp', 'subdir' ],
39 'content', [ 'content', 'subdir' ],
40 'cmd-tstamp', [ 'cmd-tstamp', 'subdir' ],
41 'cmd-content', [ 'cmd-content', 'subdir' ])
43 test
.write('SConstruct', """\
44 DefaultEnvironment(tools=[])
46 def writeTarget(target, source, env):
47 f = open(str(target[0]), 'w')
52 test_bld_dir = Builder(
53 action=writeTarget, source_factory=Dir, source_scanner=DirScanner
55 test_bld_file = Builder(action=writeTarget)
56 env = Environment(tools=[])
57 env['BUILDERS']['TestDir'] = test_bld_dir
58 env['BUILDERS']['TestFile'] = test_bld_file
60 env_tstamp = env.Clone()
61 env_tstamp.Decider('timestamp-newer')
62 env_tstamp.TestFile(source='junk.txt', target='tstamp/junk.out')
63 env_tstamp.TestDir(source='tstamp', target='tstamp.out')
64 env_tstamp.Command('cmd-tstamp-noscan.out', 'cmd-tstamp', writeTarget)
66 'cmd-tstamp.out', 'cmd-tstamp', writeTarget, source_scanner=DirScanner
69 env_content = env.Clone()
70 env_content.Decider('content')
71 env_content.TestFile(source='junk.txt', target='content/junk.out')
72 env_content.TestDir(source='content', target='content.out')
73 env_content.Command('cmd-content-noscan.out', 'cmd-content', writeTarget)
75 'cmd-content.out', 'cmd-content', writeTarget, source_scanner=DirScanner
79 test
.write(['tstamp', 'foo.txt'], 'foo.txt 1\n')
80 test
.write(['tstamp', '#hash.txt'], 'hash.txt 1\n')
81 test
.write(['tstamp', 'subdir', 'bar.txt'], 'bar.txt 1\n')
82 test
.write(['tstamp', 'subdir', '#hash.txt'], 'hash.txt 1\n')
83 test
.write(['content', 'foo.txt'], 'foo.txt 1\n')
84 test
.write(['content', '#hash.txt'], 'hash.txt 1\n')
85 test
.write(['content', 'subdir', 'bar.txt'], 'bar.txt 1\n')
86 test
.write(['content', 'subdir', '#hash.txt'], 'hash.txt 1\n')
87 test
.write(['cmd-tstamp', 'foo.txt'], 'foo.txt 1\n')
88 test
.write(['cmd-tstamp', '#hash.txt'], 'hash.txt 1\n')
89 test
.write(['cmd-tstamp', 'subdir', 'bar.txt'], 'bar.txt 1\n')
90 test
.write(['cmd-tstamp', 'subdir', '#hash.txt'], 'hash.txt 1\n')
91 test
.write(['cmd-content', 'foo.txt'], 'foo.txt 1\n')
92 test
.write(['cmd-content', '#hash.txt'], '#hash.txt 1\n')
93 test
.write(['cmd-content', 'subdir', 'bar.txt'], 'bar.txt 1\n')
94 test
.write(['cmd-content', 'subdir', '#hash.txt'], 'hash.txt 1\n')
95 test
.write('junk.txt', 'junk.txt\n')
97 test
.run(arguments
=".", stderr
=None)
98 test
.must_match('tstamp.out', 'stuff\n', mode
='r')
99 test
.must_match('content.out', 'stuff\n', mode
='r')
100 test
.must_match('cmd-tstamp.out', 'stuff\n', mode
='r')
101 test
.must_match('cmd-content.out', 'stuff\n', mode
='r')
102 test
.must_match('cmd-tstamp-noscan.out', 'stuff\n', mode
='r')
103 test
.must_match('cmd-content-noscan.out', 'stuff\n', mode
='r')
105 test
.up_to_date(arguments
='tstamp.out')
106 test
.up_to_date(arguments
='content.out')
107 test
.up_to_date(arguments
='cmd-tstamp.out')
108 test
.up_to_date(arguments
='cmd-content.out')
109 test
.up_to_date(arguments
='cmd-tstamp-noscan.out')
110 test
.up_to_date(arguments
='cmd-content-noscan.out')
112 test
.sleep() # delay for timestamps
114 test
.write(['tstamp', 'foo.txt'], 'foo.txt 2\n')
115 test
.not_up_to_date(arguments
='tstamp.out')
117 test
.write(['tstamp', 'new.txt'], 'new.txt\n')
118 test
.not_up_to_date(arguments
='tstamp.out')
120 test
.write(['content', 'foo.txt'], 'foo.txt 2\n')
121 test
.not_up_to_date(arguments
='content.out')
123 test
.write(['content', 'new.txt'], 'new.txt\n')
124 test
.not_up_to_date(arguments
='content.out')
126 test
.write(['cmd-tstamp', 'foo.txt'], 'foo.txt 2\n')
127 test
.not_up_to_date(arguments
='cmd-tstamp.out')
128 test
.up_to_date(arguments
='cmd-tstamp-noscan.out')
130 test
.write(['cmd-tstamp', 'new.txt'], 'new.txt\n')
131 test
.not_up_to_date(arguments
='cmd-tstamp.out')
132 test
.up_to_date(arguments
='cmd-tstamp-noscan.out')
134 test
.write(['cmd-content', 'foo.txt'], 'foo.txt 2\n')
135 test
.not_up_to_date(arguments
='cmd-content.out')
136 test
.up_to_date(arguments
='cmd-content-noscan.out')
138 test
.write(['cmd-content', 'new.txt'], 'new.txt\n')
139 test
.not_up_to_date(arguments
='cmd-content.out')
140 test
.up_to_date(arguments
='cmd-content-noscan.out')
142 test
.write(['tstamp', 'subdir', 'bar.txt'], 'bar.txt 2\n')
143 test
.not_up_to_date(arguments
='tstamp.out')
145 test
.write(['tstamp', 'subdir', 'new.txt'], 'new.txt\n')
146 test
.not_up_to_date(arguments
='tstamp.out')
148 test
.write(['content', 'subdir', 'bar.txt'], 'bar.txt 2\n')
149 test
.not_up_to_date(arguments
='content.out')
151 test
.write(['content', 'subdir', 'new.txt'], 'new.txt\n')
152 test
.not_up_to_date(arguments
='content.out')
154 test
.write(['cmd-tstamp', 'subdir', 'bar.txt'], 'bar.txt 2\n')
155 test
.not_up_to_date(arguments
='cmd-tstamp.out')
156 test
.up_to_date(arguments
='cmd-tstamp-noscan.out')
158 test
.write(['cmd-tstamp', 'subdir', 'new.txt'], 'new.txt\n')
159 test
.not_up_to_date(arguments
='cmd-tstamp.out')
160 test
.up_to_date(arguments
='cmd-tstamp-noscan.out')
162 test
.write(['cmd-content', 'subdir', 'bar.txt'], 'bar.txt 2\n')
163 test
.not_up_to_date(arguments
='cmd-content.out')
164 test
.up_to_date(arguments
='cmd-content-noscan.out')
166 test
.write(['cmd-content', 'subdir', 'new.txt'], 'new.txt\n')
167 test
.not_up_to_date(arguments
='cmd-content.out')
168 test
.up_to_date(arguments
='cmd-content-noscan.out')
170 test
.write('junk.txt', 'junk.txt 2\n')
171 test
.not_up_to_date(arguments
='tstamp.out')
172 test
.not_up_to_date(arguments
='content.out')
178 # indent-tabs-mode:nil
180 # vim: set expandtab tabstop=4 shiftwidth=4: