1a9a72b7f854421b9ba5328243952216d3e10226
[scons.git] / test / option--C.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 import os
28 import types
29
30 import TestSCons
31
32 def match_normcase(lines, matches):
33     if not type(lines) is types.ListType:
34         lines = lines.split("\n")
35     if not type(matches) is types.ListType:
36         matches = matches.split("\n")
37     if len(lines) != len(matches):
38         return
39     for i in range(len(lines)):
40         if os.path.normcase(lines[i]) != os.path.normcase(matches[i]):
41             return
42     return 1
43
44 test = TestSCons.TestSCons(match=match_normcase)
45
46 wpath = test.workpath()
47 wpath_sub = test.workpath('sub')
48 wpath_sub_dir = test.workpath('sub', 'dir')
49 wpath_sub_foo_bar = test.workpath('sub', 'foo', 'bar')
50
51 test.subdir('sub', ['sub', 'dir'])
52
53 test.write('SConstruct', """
54 import os
55 print "SConstruct", os.getcwd()
56 """)
57
58 test.write(['sub', 'SConstruct'], """
59 import os
60 print GetBuildPath('..')
61 """)
62
63 test.write(['sub', 'dir', 'SConstruct'], """
64 import os
65 env = Environment(FOO='foo', BAR='bar')
66 print env.GetBuildPath('../$FOO/$BAR')
67 """)
68
69 test.run(arguments = '-C sub .',
70          stdout = "scons: Entering directory `%s'\n" % wpath_sub \
71              + test.wrap_stdout(read_str = '%s\n' % wpath,
72                                 build_str = "scons: `.' is up to date.\n"))
73
74 test.run(arguments = '-C sub -C dir .',
75          stdout = "scons: Entering directory `%s'\n" % wpath_sub_dir \
76              + test.wrap_stdout(read_str = '%s\n' % wpath_sub_foo_bar,
77                                 build_str = "scons: `.' is up to date.\n"))
78
79 test.run(arguments = ".",
80          stdout = test.wrap_stdout(read_str = 'SConstruct %s\n' % wpath,
81                                    build_str = "scons: `.' is up to date.\n"))
82
83 test.run(arguments = '--directory=sub/dir .',
84          stdout = "scons: Entering directory `%s'\n" % wpath_sub_dir \
85              + test.wrap_stdout(read_str = '%s\n' % wpath_sub_foo_bar,
86                                 build_str = "scons: `.' is up to date.\n"))
87
88 test.run(arguments = '-C %s -C %s .' % (wpath_sub_dir, wpath_sub),
89          stdout = "scons: Entering directory `%s'\n" % wpath_sub \
90              + test.wrap_stdout(read_str = '%s\n' % wpath,
91                                 build_str = "scons: `.' is up to date.\n"))
92
93 test.pass_test()
94
95 # Local Variables:
96 # tab-width:4
97 # indent-tabs-mode:nil
98 # End:
99 # vim: set expandtab tabstop=4 shiftwidth=4: