Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / Mkdir.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 Verify that the Mkdir() Action works.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.subdir('work1', 'work2')
38
39 test.write(['work1', 'SConstruct'], """
40 Execute(Mkdir('d1'))
41 def cat(env, source, target):
42     target = str(target[0])
43     source = map(str, source)
44     f = open(target, "wb")
45     for src in source:
46         f.write(open(src, "rb").read())
47     f.close()
48 Cat = Action(cat)
49 env = Environment()
50 env.Command('f2.out', 'f2.in', [Cat, Mkdir("d3")])
51 env = Environment(DIR = 'd4')
52 env.Command('f5.out', 'f5.in', [Mkdir("$DIR"), Cat])
53 env.Command('f6.out', 'f6.in', [Cat,
54                                 Mkdir("Mkdir-$SOURCE"),
55                                 Mkdir("$TARGET-Mkdir")])
56 # Make sure that a user-defined Mkdir builder on a directory
57 # doesn't get executed twice if it has to get called to create
58 # directory for another target.
59 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
60 env.Command('hello/world', None, [Touch('$TARGET')])
61 """)
62
63 test.write(['work1', 'f2.in'], "f2.in\n")
64 test.write(['work1', 'f5.in'], "f5.in\n")
65 test.write(['work1', 'f6.in'], "f6.in\n")
66
67 expect = test.wrap_stdout(read_str = 'Mkdir("d1")\n',
68                           build_str = """\
69 cat(["f2.out"], ["f2.in"])
70 Mkdir("d3")
71 Mkdir("d4")
72 cat(["f5.out"], ["f5.in"])
73 cat(["f6.out"], ["f6.in"])
74 Mkdir("Mkdir-f6.in")
75 Mkdir("f6.out-Mkdir")
76 Mkdir("hello")
77 Touch("%s")
78 """ % (os.path.join('hello', 'world')))
79 test.run(chdir = 'work1', options = '-n', arguments = '.', stdout = expect)
80
81 test.must_not_exist(['work1', 'd1'])
82 test.must_not_exist(['work1', 'f2.out'])
83 test.must_not_exist(['work1', 'd3'])
84 test.must_not_exist(['work1', 'd4'])
85 test.must_not_exist(['work1', 'f5.out'])
86 test.must_not_exist(['work1', 'f6.out'])
87 test.must_not_exist(['work1', 'Mkdir-f6.in'])
88 test.must_not_exist(['work1', 'f6.out-Mkdir'])
89
90 test.run(chdir = 'work1')
91
92 test.must_exist(['work1', 'd1'])
93 test.must_match(['work1', 'f2.out'], "f2.in\n")
94 test.must_exist(['work1', 'd3'])
95 test.must_exist(['work1', 'd4'])
96 test.must_match(['work1', 'f5.out'], "f5.in\n")
97 test.must_exist(['work1', 'f6.out'])
98 test.must_exist(['work1', 'Mkdir-f6.in'])
99 test.must_exist(['work1', 'f6.out-Mkdir'])
100 test.must_exist(['work1', 'hello'])
101 test.must_exist(['work1', 'hello/world'])
102
103 test.write(['work1', 'd1', 'file'], "d1/file\n")
104 test.write(['work1', 'd3', 'file'], "d3/file\n")
105 test.write(['work1', 'Mkdir-f6.in', 'file'], "Mkdir-f6.in/file\n")
106 test.write(['work1', 'f6.out-Mkdir', 'file'], "f6.out-Mkdir/file\n")
107 test.write(['work1', 'hello', 'file'], "hello/file\n")
108
109
110
111
112 test.write(['work2', 'SConstruct'], """\
113 import os
114 def catdir(env, source, target):
115     target = str(target[0])
116     source = map(str, source)
117     outfp = open(target, "wb")
118     for src in source:
119         l = os.listdir(src)
120         l.sort()
121         for f in l:
122             f = os.path.join(src, f)
123             if os.path.isfile(f):
124                 outfp.write(open(f, "rb").read())
125     outfp.close()
126 CatDir = Builder(action = catdir)
127 env = Environment(BUILDERS = {'CatDir' : CatDir})
128 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
129 env.Command('hello/file1.out', 'file1.in', [Copy('$TARGET', '$SOURCE')])
130 env.Command('hello/file2.out', 'file2.in', [Copy('$TARGET', '$SOURCE')])
131 env.CatDir('output', Dir('hello'))
132 """)
133
134 test.write(['work2', 'file1.in'], "work2/file1.in\n")
135 test.write(['work2', 'file2.in'], "work2/file2.in\n")
136
137 test.run(chdir = 'work2', arguments = 'hello/file2.out output')
138
139 test.must_match(['work2', 'output'], "work2/file1.in\nwork2/file2.in\n")
140
141 test.pass_test()