Merge branch 'master' into jbrill-msvc-detect
[scons.git] / test / MSVC / msvc.py
blobe81ecea7e8b8acf7016b60cd01914348c3c7e61d
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 Verify basic invocation of Microsoft Visual C/C++, including use
28 of a precompiled header with the $CCFLAGS variable.
29 """
32 import time
34 import TestSCons
36 test = TestSCons.TestSCons(match=TestSCons.match_re)
38 test.skip_if_not_msvc()
40 test.dir_fixture('msvc_fixture')
42 #####
43 # Test the basics
45 # Visual Studio 8 has deprecated the /Yd option and prints warnings
46 # about it, so ignore stderr when running SCons.
48 test.run(arguments='test.exe', stderr=None)
49 test.must_exist(test.workpath('test.exe'))
50 test.must_exist(test.workpath('test.res'))
51 test.must_exist(test.workpath('test.pdb'))
52 test.must_exist(test.workpath('StdAfx.pch'))
53 test.must_exist(test.workpath('StdAfx.obj'))
55 test.run(program=test.workpath('test.exe'), stdout='2001 test 1\n')
57 test.write('resource.h', '''
58 #define IDS_TEST 2002
59 ''')
60 test.run(arguments='test.exe', stderr=None)
61 test.run(program=test.workpath('test.exe'), stdout='2002 test 1\n')
63 test.write('test.rc', '''
64 #include "resource.h"
66 STRINGTABLE DISCARDABLE
67 BEGIN
68 IDS_TEST "test 2"
69 END
70 ''')
71 test.run(arguments='test.exe', stderr=None)
72 test.run(program=test.workpath('test.exe'), stdout='2002 test 2\n')
74 test.run(arguments='-c .')
75 test.must_not_exist(test.workpath('test.exe'))
76 test.must_not_exist(test.workpath('test.pdb'))
77 test.must_not_exist(test.workpath('test.res'))
78 test.must_not_exist(test.workpath('StdAfx.pch'))
79 test.must_not_exist(test.workpath('StdAfx.obj'))
81 test.run(arguments='test.exe', stderr=None)
82 test.must_exist(test.workpath('test.pdb'))
83 test.must_exist(test.workpath('StdAfx.pch'))
84 test.must_exist(test.workpath('StdAfx.obj'))
86 test.run(arguments='-c test.pdb')
87 test.must_not_exist(test.workpath('test.exe'))
88 test.must_not_exist(test.workpath('test.obj'))
89 test.must_not_exist(test.workpath('test.pdb'))
90 test.must_not_exist(test.workpath('StdAfx.pch'))
91 test.must_not_exist(test.workpath('StdAfx.obj'))
93 test.run(arguments='StdAfx.pch', stderr=None)
94 test.must_not_exist(test.workpath('test.pdb'))
95 test.must_exist(test.workpath('StdAfx.pch'))
96 test.must_exist(test.workpath('StdAfx.obj'))
98 test.run(arguments='-c test.exe')
99 test.must_not_exist(test.workpath('test.exe'))
100 test.must_not_exist(test.workpath('test.obj'))
101 test.must_not_exist(test.workpath('test.pdb'))
102 test.must_not_exist(test.workpath('StdAfx.pch'))
103 test.must_not_exist(test.workpath('StdAfx.obj'))
105 test.run(arguments='test.obj', stderr=None)
106 test.must_not_exist(test.workpath('test.pdb'))
107 test.must_exist(test.workpath('test.obj'))
109 start = time.perf_counter()
110 test.run(arguments='fast.obj', stderr=None)
111 fast = time.perf_counter() - start
113 start = time.perf_counter()
114 test.run(arguments='slow.obj', stderr=None)
115 slow = time.perf_counter() - start
117 # TODO: Reevaluate if having this part of the test makes sense any longer
118 # using precompiled headers should be faster
119 limit = slow*1.00
120 if fast >= limit:
121 print("Using precompiled headers was not fast enough:")
122 print("slow.obj: %.3fs" % slow)
123 print("fast.obj: %.3fs (expected less than %.3fs)" % (fast, limit))
124 test.fail_test()
126 # Modifying resource.h should cause both the resource and precompiled header to be rebuilt:
127 test.write('resource.h', '''
128 #define IDS_TEST 2003
129 ''')
131 test.not_up_to_date(arguments='test.res', stderr=None)
132 test.not_up_to_date(arguments='StdAfx.pch', stderr=None)
133 test.not_up_to_date(arguments='test.exe', stderr=None)
134 test.run(program=test.workpath('test.exe'), stdout='2003 test 2\n')
136 test.pass_test()
138 # Local Variables:
139 # tab-width:4
140 # indent-tabs-mode:nil
141 # End:
142 # vim: set expandtab tabstop=4 shiftwidth=4: