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_NOTFOUND_POLICY construction variable and functions.
32 test
= TestSCons
.TestSCons()
33 test
.skip_if_not_msvc()
37 # Test construction variable with valid symbols
38 test
.write('SConstruct', textwrap
.dedent(
41 DefaultEnvironment(tools=[])
42 for symbol in ['Error', 'Exception', 'Warn', 'Warning', 'Ignore', 'Suppress']:
43 for policy in [symbol, symbol.upper(), symbol.lower()]:
44 env = Environment(MSVC_NOTFOUND_POLICY=policy, tools=['msvc'])
48 test
.run(arguments
='-Q -s', stdout
='')
50 # Test construction variable with invalid symbol
51 test
.write('SConstruct', textwrap
.dedent(
53 DefaultEnvironment(tools=[])
54 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Undefined', tools=['msvc'])
57 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
58 expect
= "MSVCArgumentError: Value specified for MSVC_NOTFOUND_POLICY is not supported: 'Undefined'."
59 test
.must_contain_all(test
.stderr(), expect
)
61 # Test environment construction with global policy
62 test
.write('SConstruct', textwrap
.dedent(
64 from SCons.Tool.MSCommon import msvc_set_notfound_policy
65 msvc_set_notfound_policy('Exception')
66 DefaultEnvironment(tools=[])
67 env = Environment(MSVC_VERSION='12.9', tools=['msvc'])
70 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
71 expect
= "MSVCVersionNotFound: MSVC version '12.9' was not found."
72 test
.must_contain_all(test
.stderr(), expect
)
74 # Test environment construction with global policy and construction variable ignored
75 test
.write('SConstruct', textwrap
.dedent(
77 from SCons.Tool.MSCommon import msvc_set_notfound_policy
78 msvc_set_notfound_policy('Exception')
79 DefaultEnvironment(tools=[])
80 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY=None, tools=['msvc'])
83 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
84 expect
= "MSVCVersionNotFound: MSVC version '12.9' was not found."
85 test
.must_contain_all(test
.stderr(), expect
)
87 # Test environment construction with construction variable
88 test
.write('SConstruct', textwrap
.dedent(
90 DefaultEnvironment(tools=[])
91 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Error', tools=['msvc'])
94 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
95 expect
= "MSVCVersionNotFound: MSVC version '12.9' was not found."
96 test
.must_contain_all(test
.stderr(), expect
)
98 # Test environment construction with global policy
99 test
.write('SConstruct', textwrap
.dedent(
101 from SCons.Tool.MSCommon import msvc_set_notfound_policy
102 msvc_set_notfound_policy('Warning')
103 DefaultEnvironment(tools=[])
104 env = Environment(MSVC_VERSION='12.9', tools=['msvc'])
107 test
.run(arguments
="-Q -s --warn=visual-c-missing .", status
=0, stderr
=None)
108 expect
= "scons: warning: MSVC version '12.9' was not found."
109 test
.must_contain_all(test
.stderr(), expect
)
111 # Test environment construction with construction variable
112 test
.write('SConstruct', textwrap
.dedent(
114 DefaultEnvironment(tools=[])
115 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Warning', tools=['msvc'])
118 test
.run(arguments
="-Q -s --warn=visual-c-missing .", status
=0, stderr
=None)
119 expect
= "scons: warning: MSVC version '12.9' was not found."
120 test
.must_contain_all(test
.stderr(), expect
)
122 # Test environment construction with construction variable (override global)
123 test
.write('SConstruct', textwrap
.dedent(
125 from SCons.Tool.MSCommon import msvc_set_notfound_policy
126 msvc_set_notfound_policy('Exception')
127 DefaultEnvironment(tools=[])
128 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Ignore', tools=['msvc'])
131 test
.run(arguments
='-Q -s', stdout
='')
137 # indent-tabs-mode:nil
139 # vim: set expandtab tabstop=4 shiftwidth=4: