Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / option--cd.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 """
28 Test the --cache-disable option when retrieving derived files from a
29 CacheDir.
30 """
31
32 import os.path
33 import shutil
34
35 import TestSCons
36
37 test = TestSCons.TestSCons()
38
39 test.subdir('cache', 'src')
40
41 test.write(['src', 'SConstruct'], """
42 def cat(env, source, target):
43     target = str(target[0])
44     open('cat.out', 'ab').write(target + "\\n")
45     source = map(str, source)
46     f = open(target, "wb")
47     for src in source:
48         f.write(open(src, "rb").read())
49     f.close()
50 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
51 env.Cat('aaa.out', 'aaa.in')
52 env.Cat('bbb.out', 'bbb.in')
53 env.Cat('ccc.out', 'ccc.in')
54 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
55 CacheDir(r'%s')
56 """ % test.workpath('cache'))
57
58 test.write(['src', 'aaa.in'], "aaa.in\n")
59 test.write(['src', 'bbb.in'], "bbb.in\n")
60 test.write(['src', 'ccc.in'], "ccc.in\n")
61
62 # Verify that a normal build works correctly, and clean up.
63 # This should populate the cache with our derived files.
64 test.run(chdir = 'src', arguments = '.')
65
66 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n")
67 test.must_match(['src', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n")
68
69 test.up_to_date(chdir = 'src', arguments = '.')
70
71 test.run(chdir = 'src', arguments = '-c .')
72 test.unlink(['src', 'cat.out'])
73
74 # Verify that we now retrieve the derived files from cache,
75 # not rebuild them.  Then clean up.
76 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
77 Retrieved `aaa.out' from cache
78 Retrieved `bbb.out' from cache
79 Retrieved `ccc.out' from cache
80 Retrieved `all' from cache
81 """))
82
83 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n")
84 test.must_not_exist(test.workpath('src', 'cat.out'))
85
86 test.up_to_date(chdir = 'src', arguments = '.')
87
88 test.run(chdir = 'src', arguments = '-c .')
89
90 # Verify that when run with --cache-disable, we rebuild the files even
91 # though they're available from the cache.  Then clean up.
92 test.run(chdir = 'src',
93          arguments = '--cache-disable .',
94          stdout = test.wrap_stdout("""\
95 cat(["aaa.out"], ["aaa.in"])
96 cat(["bbb.out"], ["bbb.in"])
97 cat(["ccc.out"], ["ccc.in"])
98 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
99 """))
100
101 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n")
102 test.must_match(['src', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n")
103
104 test.up_to_date(chdir = 'src', arguments = '.')
105
106 test.run(chdir = 'src', arguments = '-c .')
107 test.unlink(['src', 'cat.out'])
108
109 # Verify that when run with --no-cache, we rebuild the files even
110 # though they're available from the cache.  Then clean up.
111 test.run(chdir = 'src',
112          arguments = '--no-cache .',
113          stdout = test.wrap_stdout("""\
114 cat(["aaa.out"], ["aaa.in"])
115 cat(["bbb.out"], ["bbb.in"])
116 cat(["ccc.out"], ["ccc.in"])
117 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
118 """))
119
120 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n")
121 test.must_match(['src', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n")
122
123 test.up_to_date(chdir = 'src', arguments = '.')
124
125 test.run(chdir = 'src', arguments = '-c .')
126 test.unlink(['src', 'cat.out'])
127
128 # All done.
129 test.pass_test()