Updates and slight refactor in fix
[scons.git] / test / MSVC / MSVC_NOTFOUND_POLICY.py
blobdf1719cf2991d28556a09e318c12e219e43d4ffb
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Test the MSVC_NOTFOUND_POLICY construction variable and functions.
28 """
30 import TestSCons
32 test = TestSCons.TestSCons()
33 test.skip_if_not_msvc()
35 import textwrap
37 # Test construction variable with valid symbols
38 test.write('SConstruct', textwrap.dedent(
39 """
40 env_list = []
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'])
45 env_list.append(env)
46 """
48 test.run(arguments='-Q -s', stdout='')
50 # Test construction variable with invalid symbol
51 test.write('SConstruct', textwrap.dedent(
52 """
53 DefaultEnvironment(tools=[])
54 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Undefined', tools=['msvc'])
55 """
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(
63 """
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'])
68 """
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(
76 """
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'])
81 """
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(
89 """
90 DefaultEnvironment(tools=[])
91 env = Environment(MSVC_VERSION='12.9', MSVC_NOTFOUND_POLICY='Error', tools=['msvc'])
92 """
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='')
133 test.pass_test()
135 # Local Variables:
136 # tab-width:4
137 # indent-tabs-mode:nil
138 # End:
139 # vim: set expandtab tabstop=4 shiftwidth=4: