Merged revisions 1784-1824 via svnmerge from
[scons.git] / test / Options / BoolOption.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 BoolOption 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()
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 import BoolOption
54
55 opts = Options(args=ARGUMENTS)
56 opts.AddOptions(
57     BoolOption('warnings', 'compilation with -Wall and similiar', 1),
58     BoolOption('profile', 'create profiling informations', 0),
59     )
60
61 env = Environment(options=opts)
62 Help(opts.GenerateHelpText(env))
63
64 print env['warnings']
65 print env['profile']
66
67 Default(env.Alias('dummy', None))
68 """)
69
70
71
72 test.run()
73 check([str(True), str(False)])
74
75 test.run(arguments='warnings=0 profile=no profile=true')
76 check([str(False), str(True)])
77
78 expect_stderr = """
79 scons: *** Error converting option: warnings
80 Invalid value for boolean option: irgendwas
81 File "%(SConstruct_path)s", line 9, in ?
82 """ % locals()
83
84 test.run(arguments='warnings=irgendwas', stderr = expect_stderr, status=2)
85
86
87
88 test.pass_test()