summaryrefslogtreecommitdiffstats
path: root/SCons/Tool/MSCommon/MSVC/ScriptArgumentsTests.py
blob: 5a5abad4053589649278df9a1cbb813529d23f6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""
Test batch file argument functions for Microsoft Visual C/C++.
"""

import unittest

import SCons.Environment

from SCons.Tool.MSCommon import vc
from SCons.Tool.MSCommon import vcTests

from SCons.Tool.MSCommon.MSVC import Config
from SCons.Tool.MSCommon.MSVC import Util
from SCons.Tool.MSCommon.MSVC import WinSDK
from SCons.Tool.MSCommon.MSVC import ScriptArguments

from SCons.Tool.MSCommon.MSVC.Exceptions import (
    MSVCInternalError,
    MSVCArgumentError,
    MSVCToolsetVersionNotFound,
    MSVCSDKVersionNotFound,
    MSVCSpectreLibsNotFound,
)

def Environment(**kwargs):
    tools_key = 'tools'
    if tools_key not in kwargs:
        tools = []
    else:
        tools = kwargs[tools_key]
        del kwargs[tools_key]
    return SCons.Environment.Base(tools=tools, **kwargs)


def _sdk_versions_comps_dict_seen(installed_version_pairs):

    sdk_versions_comps_dict = {}
    sdk_versions_seen = set()

    _sdk_version_list_seen = {}
    for version_def, _ in installed_version_pairs:
        sdk_versions_comps_dict[version_def.msvc_version] = {}
        for msvc_uwp_app in (True, False):
            sdk_version_list = WinSDK.get_msvc_sdk_version_list(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
            key = tuple(sdk_version_list)
            if key in _sdk_version_list_seen:
                sdk_comps_list = _sdk_version_list_seen[key]
            else:
                sdk_versions_seen.update(sdk_version_list)
                sdk_comps_list = [Util.msvc_sdk_version_components(sdk_version) for sdk_version in sdk_version_list]
                _sdk_version_list_seen[key] = sdk_comps_list
            sdk_versions_comps_dict[version_def.msvc_version][msvc_uwp_app] = sdk_comps_list

    return sdk_versions_comps_dict, sdk_versions_seen

def _sdk_versions_notfound(installed_version_pairs, sdk_versions_comps_dict, sdk_versions_seen):

    sdk_versions_notfound_dict = {}
    sdk_notfound_seen = {}

    def _make_notfound_version(sdk_seen, sdk_def):
        if len(sdk_def.sdk_comps) == 4:
            nloop = 0
            while nloop < 10:
                ival = int(sdk_def.sdk_comps[-2])
                if ival == 0:
                    ival = 1000000
                ival -= 1
                version = '{}.{}.{:05d}.{}'.format(
                    sdk_def.sdk_comps[0], sdk_def.sdk_comps[1], ival, sdk_def.sdk_comps[-1]
                )
                if version not in sdk_seen:
                    return version
                nloop += 1
        return None

    for version_def, _ in installed_version_pairs:
        sdk_versions_notfound_dict[version_def.msvc_version] = {}
        for msvc_uwp_app in (True, False):
            sdk_notfound_list = []
            sdk_versions_notfound_dict[version_def.msvc_version][msvc_uwp_app] = sdk_notfound_list
            sdk_comps_list = sdk_versions_comps_dict[version_def.msvc_version][msvc_uwp_app]
            for sdk_def in sdk_comps_list:
                if sdk_def.sdk_version in sdk_notfound_seen:
                    sdk_notfound_version = sdk_notfound_seen[sdk_def.sdk_version]
                else:
                    sdk_notfound_version = _make_notfound_version(sdk_versions_seen, sdk_def)
                    sdk_notfound_seen[sdk_def.sdk_version] = sdk_notfound_version
                if not sdk_notfound_version:
                    continue
                sdk_notfound_list.append(sdk_notfound_version)

    return sdk_versions_notfound_dict

class Data:

    # all versions
    ALL_VERSIONS_PAIRS = []

    # installed versions
    INSTALLED_VERSIONS_PAIRS = []

    # VS2015 installed
    HAVE140_TOOLSET = ScriptArguments._msvc_have140_toolset()

    for vcver in Config.MSVC_VERSION_SUFFIX.keys():
        version_def = Util.msvc_version_components(vcver)
        vc_dir = vc.find_vc_pdir(None, vcver)
        t = (version_def, vc_dir)
        ALL_VERSIONS_PAIRS.append(t)
        if vc_dir:
            INSTALLED_VERSIONS_PAIRS.append(t)

    HAVE_MSVC = True if len(INSTALLED_VERSIONS_PAIRS) else False

    SDK_VERSIONS_COMPS_DICT, SDK_VERSIONS_SEEN = _sdk_versions_comps_dict_seen(INSTALLED_VERSIONS_PAIRS)

    SDK_VERSIONS_NOTFOUND_DICT = _sdk_versions_notfound(
        INSTALLED_VERSIONS_PAIRS, SDK_VERSIONS_COMPS_DICT, SDK_VERSIONS_SEEN
    )

    @classmethod
    def msvc_sdk_version_list_components(cls, msvc_version, msvc_uwp_app=False):
        comps_dict = cls.SDK_VERSIONS_COMPS_DICT.get(msvc_version, {})
        comps_list = comps_dict.get(msvc_uwp_app, [])
        return comps_list

    @classmethod
    def msvc_sdk_version(cls, msvc_version, msvc_uwp_app=False):
        comps_dict = cls.SDK_VERSIONS_COMPS_DICT.get(msvc_version, {})
        comps_list = comps_dict.get(msvc_uwp_app, [])
        if not comps_list:
            sdk_version = '10.0.20348.0'
        else:
            sdk_version = comps_list[0].sdk_version
        return sdk_version

    @classmethod
    def msvc_sdk_notfound_version(cls, msvc_version, msvc_uwp_app=False):
        notfound_dict = cls.SDK_VERSIONS_NOTFOUND_DICT.get(msvc_version, {})
        notfound_list = notfound_dict.get(msvc_uwp_app, [])
        if not notfound_list:
            notfound_version = '10.0.00000.1'
        else:
            notfound_version = notfound_list[0]
        return notfound_version

    @classmethod
    def msvc_toolset_notfound_dict(cls):
        return vcTests.Data.msvc_toolset_notfound_dict()

    @classmethod
    def msvc_toolset_notfound_version(cls, msvc_version):
        d = cls.msvc_toolset_notfound_dict()
        notfound_versions = d.get(msvc_version,[])
        if not notfound_versions:
            notfound_version = msvc_version + '0.00001'
        else:
            notfound_version = notfound_versions[0]
        return notfound_version

class Patch:

    class Config:

        class MSVC_SDK_VERSIONS:

            MSVC_SDK_VERSIONS = Config.MSVC_SDK_VERSIONS

            @classmethod
            def enable_copy(cls):
                hook = set(cls.MSVC_SDK_VERSIONS)
                Config.MSVC_SDK_VERSIONS = hook
                return hook

            @classmethod
            def restore(cls):
                Config.MSVC_SDK_VERSIONS = cls.MSVC_SDK_VERSIONS

class ScriptArgumentsTests(unittest.TestCase):

    def test_verify(self):
        MSVC_SDK_VERSIONS = Patch.Config.MSVC_SDK_VERSIONS.enable_copy()
        MSVC_SDK_VERSIONS.add('99.0')
        with self.assertRaises(MSVCInternalError):
            ScriptArguments.verify()
        Patch.Config.MSVC_SDK_VERSIONS.restore()

    def test_msvc_script_arguments_defaults(self):
        func = ScriptArguments.msvc_script_arguments
        env = Environment()
        # disable forcing sdk and toolset versions as arguments
        force = ScriptArguments.msvc_force_default_arguments(force=False)
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            for arg in ('', 'arch'):
                scriptargs = func(env, version_def.msvc_version, vc_dir, arg)
                self.assertTrue(scriptargs == arg, "{}({},{}) != {} [force=False]".format(
                    func.__name__, repr(version_def.msvc_version), repr(arg), repr(scriptargs)
                ))
        # enable forcing sdk and toolset versions as arguments
        ScriptArguments.msvc_force_default_arguments(force=True)
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            scriptargs = func(env, version_def.msvc_version, vc_dir, '')
            for arg in ('', 'arch'):
                scriptargs = func(env, version_def.msvc_version, vc_dir, arg)
                if version_def.msvc_vernum >= 14.0:
                    if arg and scriptargs.startswith(arg):
                        testargs = scriptargs[len(arg):].lstrip()
                    else:
                        testargs = scriptargs
                    self.assertTrue(testargs, "{}({},{}) is empty [force=True]".format(
                        func.__name__, repr(version_def.msvc_version), repr(arg)
                    ))
                else:
                    self.assertTrue(scriptargs == arg, "{}({},{}) != {} [force=True]".format(
                        func.__name__, repr(version_def.msvc_version), repr(arg), repr(scriptargs)
                    ))
        # restore forcing sdk and toolset versions as arguments
        ScriptArguments.msvc_force_default_arguments(force=force)

    def test_msvc_toolset_versions_internal(self):
        func = ScriptArguments._msvc_toolset_versions_internal
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            for full in (True, False):
                for sxs in (True, False):
                    toolset_versions = func(version_def.msvc_version, vc_dir, full=full, sxs=sxs)
                    if version_def.msvc_vernum < 14.1:
                        self.assertTrue(toolset_versions is None, "{}({},{},full={},sxs={}) is not None ({})".format(
                            func.__name__, repr(version_def.msvc_version), repr(vc_dir), repr(full), repr(sxs),
                            repr(toolset_versions)
                        ))
                    elif full:
                        self.assertTrue(len(toolset_versions), "{}({},{},full={},sxs={}) is empty".format(
                            func.__name__, repr(version_def.msvc_version), repr(vc_dir), repr(full), repr(sxs)
                        ))
                    elif sxs:
                        # sxs list can be empty
                        pass
                    else:
                        self.assertFalse(len(toolset_versions), "{}({},{},full={},sxs={}) is not empty".format(
                            func.__name__, repr(version_def.msvc_version), repr(vc_dir), repr(full), repr(sxs)
                        ))

    def test_msvc_toolset_internal(self):
        if not Data.HAVE_MSVC:
            return
        func = ScriptArguments._msvc_toolset_internal
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            toolset_versions = ScriptArguments._msvc_toolset_versions_internal(version_def.msvc_version, vc_dir, full=True, sxs=True)
            if not toolset_versions:
                continue
            for toolset_version in toolset_versions:
                _ = func(version_def.msvc_version, toolset_version, vc_dir)

    def run_msvc_script_args_none(self):
        func = ScriptArguments.msvc_script_arguments
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            for kwargs in [
                {'MSVC_SCRIPT_ARGS': None},
                {'MSVC_SCRIPT_ARGS': None, 'MSVC_UWP_APP': None},
                {'MSVC_SCRIPT_ARGS': None, 'MSVC_TOOLSET_VERSION': None},
                {'MSVC_SCRIPT_ARGS': None, 'MSVC_SDK_VERSION': None},
                {'MSVC_SCRIPT_ARGS': None, 'MSVC_SPECTRE_LIBS': None},
            ]:
                env = Environment(**kwargs)
                _ = func(env, version_def.msvc_version, vc_dir, '')

    def run_msvc_script_args(self):
        func = ScriptArguments.msvc_script_arguments
        for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
            if version_def.msvc_vernum >= 14.1:
                # VS2017 and later

                toolset_versions = [
                    Util.msvc_extended_version_components(toolset_version)
                    for toolset_version in
                    ScriptArguments._msvc_toolset_versions_internal(
                        version_def.msvc_version, vc_dir, full=True, sxs=False
                    )
                ]

                toolset_def = toolset_versions[0] if toolset_versions else Util.msvc_extended_version_components(version_def.msvc_verstr)

                earlier_toolset_versions = [toolset_def for toolset_def in toolset_versions if toolset_def.msvc_vernum != version_def.msvc_vernum]
                earlier_toolset_def = earlier_toolset_versions[0] if earlier_toolset_versions else None

                # should not raise exception (argument not validated)
                env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
                _ = func(env, version_def.msvc_version, vc_dir, '')

                for kwargs in [
                    {'MSVC_UWP_APP': False, 'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_UWP_APP': '0',   'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_UWP_APP': False, 'MSVC_SCRIPT_ARGS': 'store'},
                    {'MSVC_UWP_APP': '0',   'MSVC_SCRIPT_ARGS': 'store'},
                    {'MSVC_SPECTRE_LIBS': False, 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'},
                    {'MSVC_SPECTRE_LIBS': 'True', 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'}, # not boolean ignored
                ]:
                    env = Environment(**kwargs)
                    _ = func(env, version_def.msvc_version, vc_dir, '')

                for msvc_uwp_app in (True, False):

                    sdk_list = Data.msvc_sdk_version_list_components(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
                    for sdk_def in sdk_list:

                        if sdk_def.sdk_verstr == '8.1' and msvc_uwp_app:

                            more_tests = []

                            if earlier_toolset_def:
                                # SDK 8.1 and UWP: toolset must be 14.0
                                expect = True if earlier_toolset_def.msvc_vernum > 14.0 else False
                                more_tests.append(
                                    (expect, {
                                        'MSVC_SDK_VERSION': sdk_def.sdk_version,
                                        'MSVC_UWP_APP': msvc_uwp_app,
                                        'MSVC_TOOLSET_VERSION': earlier_toolset_def.msvc_toolset_version
                                    })
                                )

                            expect = True if version_def.msvc_vernum > 14.0 else False

                            for exc, kwargs in [
                                # script args not validated
                                (False, {
                                    'MSVC_SCRIPT_ARGS': sdk_def.sdk_version,
                                    'MSVC_UWP_APP': msvc_uwp_app
                                }),
                                # SDK 8.1 and UWP: msvc_version > 14.0
                                (True, {
                                    'MSVC_SDK_VERSION': sdk_def.sdk_version,
                                    'MSVC_UWP_APP': msvc_uwp_app
                                }),
                                # SDK 8.1 and UWP: toolset must be 14.0
                                (expect, {
                                    'MSVC_SDK_VERSION': sdk_def.sdk_version,
                                    'MSVC_UWP_APP': msvc_uwp_app,
                                    'MSVC_TOOLSET_VERSION': version_def.msvc_verstr
                                }),
                            ] + more_tests:
                                env = Environment(**kwargs)
                                if exc:
                                    with self.assertRaises(MSVCArgumentError):
                                        _ = func(env, version_def.msvc_version, vc_dir, '')
                                else:
                                    _ = func(env, version_def.msvc_version, vc_dir, '')

                        else:

                            for kwargs in [
                                {'MSVC_SCRIPT_ARGS': sdk_def.sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
                                {'MSVC_SDK_VERSION': sdk_def.sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
                            ]:
                                env = Environment(**kwargs)
                                _ = func(env, version_def.msvc_version, vc_dir, '')

                for kwargs in [
                    {'MSVC_SCRIPT_ARGS': '-vcvars_ver={}'.format(version_def.msvc_verstr)},
                    {'MSVC_TOOLSET_VERSION': version_def.msvc_verstr},
                ]:
                    env = Environment(**kwargs)
                    _ = func(env, version_def.msvc_version, vc_dir, '')

                msvc_toolset_notfound_version = Data.msvc_toolset_notfound_version(version_def.msvc_version)

                for kwargs in [
                    {'MSVC_TOOLSET_VERSION': msvc_toolset_notfound_version},
                    {'MSVC_TOOLSET_VERSION': "{}.{}.00.0".format(
                        toolset_def.msvc_toolset_comps[0], toolset_def.msvc_toolset_comps[1]
                    )},
                ]:
                    env = Environment(**kwargs)
                    with self.assertRaises(MSVCToolsetVersionNotFound):
                        _ = func(env, version_def.msvc_version, vc_dir, '')

                msvc_sdk_notfound_version = Data.msvc_sdk_notfound_version(version_def.msvc_version)

                for kwargs in [
                    {'MSVC_SDK_VERSION': msvc_sdk_notfound_version},
                ]:
                    env = Environment(**kwargs)
                    with self.assertRaises(MSVCSDKVersionNotFound):
                        _ = func(env, version_def.msvc_version, vc_dir, '')

                msvc_sdk_version = Data.msvc_sdk_version(version_def.msvc_version)

                more_tests = []

                if Data.HAVE140_TOOLSET:

                    more_tests.append(
                        # toolset != 14.0
                        ({'MSVC_TOOLSET_VERSION': '14.00.00001',
                          },
                         (MSVCArgumentError, ),
                         ),
                    )

                for kwargs, exc_t in [
                    # multiple definitions
                    ({'MSVC_UWP_APP': True,
                      'MSVC_SCRIPT_ARGS': 'uwp'
                      }, (MSVCArgumentError, ),
                     ),
                    # multiple definitions (args)
                    ({'MSVC_UWP_APP': True,
                      'MSVC_SCRIPT_ARGS': 'uwp undefined store'
                      }, (MSVCArgumentError, ),
                     ),
                    # multiple definitions
                    ({'MSVC_TOOLSET_VERSION': version_def.msvc_verstr,
                      'MSVC_SCRIPT_ARGS': "-vcvars_ver={}".format(version_def.msvc_verstr)
                      },
                     (MSVCArgumentError, ),
                     ),
                    # multiple definitions (args)
                    ({'MSVC_TOOLSET_VERSION': version_def.msvc_verstr,
                      'MSVC_SCRIPT_ARGS': "-vcvars_ver={0} undefined -vcvars_ver={0}".format(version_def.msvc_verstr)
                      },
                     (MSVCArgumentError, ),
                     ),
                    # multiple definitions
                    ({'MSVC_SDK_VERSION': msvc_sdk_version,
                      'MSVC_SCRIPT_ARGS': msvc_sdk_version
                      },
                     (MSVCArgumentError, ),
                     ),
                    # multiple definitions (args)
                    ({'MSVC_SDK_VERSION': msvc_sdk_version,
                      'MSVC_SCRIPT_ARGS': '{0} undefined {0}'.format(msvc_sdk_version)
                      },
                     (MSVCArgumentError, ),
                     ),
                    # multiple definitions
                    ({'MSVC_SPECTRE_LIBS': True,
                      'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'
                      },
                     (MSVCArgumentError, MSVCSpectreLibsNotFound),
                     ),
                    # multiple definitions (args)
                    ({'MSVC_SPECTRE_LIBS': True,
                      'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre undefined -vcvars_spectre_libs=spectre'
                      },
                     (MSVCArgumentError, MSVCSpectreLibsNotFound),
                     ),
                    # toolset < 14.0
                    ({'MSVC_TOOLSET_VERSION': '12.0',
                      },
                     (MSVCArgumentError, ),
                     ),
                    # toolset > msvc_version
                    ({'MSVC_TOOLSET_VERSION': '{}.{}'.format(version_def.msvc_major, version_def.msvc_minor+1),
                      },
                     (MSVCArgumentError, ),
                     ),
                    # version not supported
                    ({'MSVC_TOOLSET_VERSION': "{}".format(version_def.msvc_major),
                      },
                     (MSVCArgumentError, ),
                     ),
                    # version not supported
                    ({'MSVC_TOOLSET_VERSION': "{}.{}.00000.0".format(
                        toolset_def.msvc_toolset_comps[0], toolset_def.msvc_toolset_comps[1]
                      )},
                     (MSVCArgumentError, ),
                     ),
                    # version not supported
                    ({'MSVC_SDK_VERSION': '9.1',
                      },
                     (MSVCArgumentError, ),
                     ),
                    # spectre not available for UWP
                    ({'MSVC_SPECTRE_LIBS': True,
                      'MSVC_UWP_APP': True,
                      },
                     (MSVCArgumentError, MSVCSpectreLibsNotFound),
                     ),
                    # spectre not available in VS2015
                    ({'MSVC_SPECTRE_LIBS': True,
                      'MSVC_TOOLSET_VERSION': '14.00.00000',
                      },
                     (MSVCArgumentError, MSVCSpectreLibsNotFound, MSVCToolsetVersionNotFound),
                     ),
                ] + more_tests:
                    env = Environment(**kwargs)
                    with self.assertRaises(exc_t):
                        _ = func(env, version_def.msvc_version, vc_dir, '')

            elif version_def.msvc_verstr == '14.0':
                # VS2015: MSVC_SDK_VERSION and MSVC_UWP_APP

                env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
                _ = func(env, version_def.msvc_version, vc_dir, '')

                for msvc_uwp_app in (True, False):

                    sdk_list = WinSDK.get_msvc_sdk_version_list(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
                    for sdk_version in sdk_list:

                        for kwargs in [
                            {'MSVC_SCRIPT_ARGS': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
                            {'MSVC_SDK_VERSION': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
                        ]:
                            env = Environment(**kwargs)
                            _ = func(env, version_def.msvc_version, vc_dir, '')

                for kwargs in [
                    {'MSVC_SPECTRE_LIBS': True, 'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_TOOLSET_VERSION': version_def.msvc_verstr, 'MSVC_SCRIPT_ARGS': None},
                ]:
                    env = Environment(**kwargs)
                    with self.assertRaises(MSVCArgumentError):
                        _ = func(env, version_def.msvc_version, vc_dir, '')

            else:
                # VS2013 and earlier: no arguments

                env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
                with self.assertRaises(MSVCArgumentError):
                    _ = func(env, version_def.msvc_version, vc_dir, '')

                for kwargs in [
                    {'MSVC_UWP_APP': True, 'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_UWP_APP': '1',  'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_SPECTRE_LIBS': True, 'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_TOOLSET_VERSION': version_def.msvc_verstr, 'MSVC_SCRIPT_ARGS': None},
                    {'MSVC_SDK_VERSION': '10.0.00000.0', 'MSVC_SCRIPT_ARGS': None},
                ]:
                    env = Environment(**kwargs)
                    with self.assertRaises(MSVCArgumentError):
                        _ = func(env, version_def.msvc_version, vc_dir, '')

    def test_msvc_script_args_none(self):
        force = ScriptArguments.msvc_force_default_arguments(force=False)
        self.run_msvc_script_args_none()
        if Data.HAVE_MSVC:
            ScriptArguments.msvc_force_default_arguments(force=True)
            self.run_msvc_script_args_none()
        ScriptArguments.msvc_force_default_arguments(force=force)

    def test_msvc_script_args(self):
        force = ScriptArguments.msvc_force_default_arguments(force=False)
        self.run_msvc_script_args()
        ScriptArguments.msvc_force_default_arguments(force=True)
        self.run_msvc_script_args()
        ScriptArguments.msvc_force_default_arguments(force=force)

    def test_reset(self):
        ScriptArguments.reset()
        self.assertTrue(ScriptArguments._toolset_have140_cache is None, "ScriptArguments._toolset_have140_cache was not reset")
        self.assertFalse(ScriptArguments._toolset_version_cache, "ScriptArguments._toolset_version_cache was not reset")
        self.assertFalse(ScriptArguments._toolset_default_cache, "ScriptArguments._toolset_default_cache was not reset")

if __name__ == "__main__":
    unittest.main()