5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Test the MSVC_SCRIPTERROR_POLICY construction variable and functions.
33 from SCons
.Tool
.MSCommon
.vc
import get_installed_vcs_components
35 test
= TestSCons
.TestSCons()
36 test
.skip_if_not_msvc()
38 installed_versions
= get_installed_vcs_components()
39 default_version
= installed_versions
[0]
41 # Test construction variable with valid symbols
42 test
.write('SConstruct', textwrap
.dedent(
45 DefaultEnvironment(tools=[])
46 for symbol in ['Error', 'Exception', 'Warn', 'Warning', 'Ignore', 'Suppress']:
47 for policy in [symbol, symbol.upper(), symbol.lower()]:
48 env = Environment(MSVC_SCRIPTERROR_POLICY=policy, tools=['msvc'])
52 test
.run(arguments
='-Q -s', stdout
='')
54 if default_version
.msvc_vernum
>= 14.1:
55 # Need VS2017 or later for MSVC_SCRIPT_ARGS
57 # Test environment construction with construction variable (invalid)
58 test
.write('SConstruct', textwrap
.dedent(
60 DefaultEnvironment(tools=[])
61 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], MSVC_SCRIPTERROR_POLICY='Undefined', tools=['msvc'])
64 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
65 expect
= "MSVCArgumentError: Value specified for MSVC_SCRIPTERROR_POLICY is not supported: 'Undefined'."
66 test
.must_contain_all(test
.stderr(), expect
)
68 # Test environment construction with construction variable (override global)
69 test
.write('SConstruct', textwrap
.dedent(
71 from SCons.Tool.MSCommon import msvc_set_scripterror_policy
72 DefaultEnvironment(tools=[])
73 msvc_set_scripterror_policy('Exception')
74 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], MSVC_SCRIPTERROR_POLICY='Ignore', tools=['msvc'])
77 test
.run(arguments
='-Q -s', stdout
='')
79 # Test environment construction with global policy
80 test
.write('SConstruct', textwrap
.dedent(
82 from SCons.Tool.MSCommon import msvc_set_scripterror_policy
83 DefaultEnvironment(tools=[])
84 msvc_set_scripterror_policy('Exception')
85 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], tools=['msvc'])
88 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
89 expect
= "MSVCScriptExecutionError: vc script errors detected:"
90 test
.must_contain_all(test
.stderr(), expect
)
92 # Test environment construction with global policy and construction variable ignored
93 test
.write('SConstruct', textwrap
.dedent(
95 from SCons.Tool.MSCommon import msvc_set_scripterror_policy
96 DefaultEnvironment(tools=[])
97 msvc_set_scripterror_policy('Exception')
98 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], MSVC_SCRIPTERROR_POLICY=None, tools=['msvc'])
101 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
102 expect
= "MSVCScriptExecutionError: vc script errors detected:"
103 test
.must_contain_all(test
.stderr(), expect
)
105 # Test environment construction with construction variable
106 test
.write('SConstruct', textwrap
.dedent(
108 DefaultEnvironment(tools=[])
109 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], MSVC_SCRIPTERROR_POLICY='Error', tools=['msvc'])
112 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
113 expect
= "MSVCScriptExecutionError: vc script errors detected:"
114 test
.must_contain_all(test
.stderr(), expect
)
116 # Test environment construction with global policy
117 test
.write('SConstruct', textwrap
.dedent(
119 from SCons.Tool.MSCommon import msvc_set_scripterror_policy
120 DefaultEnvironment(tools=[])
121 msvc_set_scripterror_policy('Warning')
122 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], tools=['msvc'])
125 test
.run(arguments
='-Q -s', status
=0, stderr
=None)
126 expect
= "scons: warning: vc script errors detected:"
127 test
.must_contain_all(test
.stderr(), expect
)
129 # Test environment construction with construction variable
130 test
.write('SConstruct', textwrap
.dedent(
132 DefaultEnvironment(tools=[])
133 env = Environment(MSVC_SCRIPT_ARGS=['-thisdoesnotexist=somevalue'], MSVC_SCRIPTERROR_POLICY='Warning', tools=['msvc'])
136 test
.run(arguments
='-Q -s', status
=0, stderr
=None)
137 expect
= "scons: warning: vc script errors detected:"
138 test
.must_contain_all(test
.stderr(), expect
)
144 # indent-tabs-mode:nil
146 # vim: set expandtab tabstop=4 shiftwidth=4: