bb396539a15e169cd7bdefd3ed2d0e2cbdc157eb
[scons.git] / test / Deprecated / Options / PackageOption.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 PackageOption canned Option type.
29 """
30
31 import os.path
32 import string
33
34 try:
35     True, False
36 except NameError:
37     True = (0 == 0)
38     False = (0 != 0)
39
40 import TestSCons
41
42 test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
43
44 SConstruct_path = test.workpath('SConstruct')
45
46 def check(expect):
47     result = string.split(test.stdout(), '\n')
48     assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect)
49
50
51
52 test.write(SConstruct_path, """\
53 from SCons.Options.PackageOption import PackageOption
54 PO = PackageOption
55
56 from SCons.Options import PackageOption
57
58 opts = Options(args=ARGUMENTS)
59 opts.AddOptions(
60     PackageOption('x11',
61                   'use X11 installed here (yes = search some places',
62                   'yes'),
63     PO('package', 'help for package', 'yes'),
64     )
65
66 env = Environment(options=opts)
67 Help(opts.GenerateHelpText(env))
68
69 print env['x11']
70 Default(env.Alias('dummy', None))
71 """)
72
73 warnings = """
74 scons: warning: The Options class is deprecated; use the Variables class instead.
75 %s
76 scons: warning: The PackageOption\\(\\) function is deprecated; use the PackageVariable\\(\\) function instead.
77 %s""" % (TestSCons.file_expr, TestSCons.file_expr)
78
79 test.run(stderr=warnings)
80 check([str(True)])
81
82 test.run(arguments='x11=no', stderr=warnings)
83 check([str(False)])
84
85 test.run(arguments='x11=0', stderr=warnings)
86 check([str(False)])
87
88 test.run(arguments=['x11=%s' % test.workpath()], stderr=warnings)
89 check([test.workpath()])
90
91 expect_stderr = warnings + """
92 scons: \\*\\*\\* Path does not exist for option x11: /non/existing/path/
93 """ + TestSCons.file_expr
94
95 test.run(arguments='x11=/non/existing/path/', stderr=expect_stderr, status=2)
96
97
98
99 test.pass_test()
100
101 # Local Variables:
102 # tab-width:4
103 # indent-tabs-mode:nil
104 # End:
105 # vim: set expandtab tabstop=4 shiftwidth=4: