updated copyright and added csv results output to bench.py
[scons.git] / test / CXX / CXX.py
blobad00b55bf03dd49047887b895bd00ea9d4c8b8f6
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 import sys
27 import TestSCons
29 _python_ = TestSCons._python_
30 _exe = TestSCons._exe
32 test = TestSCons.TestSCons()
34 test.file_fixture('mylink.py')
35 test.dir_fixture('CXX-fixture')
37 test.write('SConstruct', """
38 env = Environment(
39 LINK=r'%(_python_)s mylink.py',
40 LINKFLAGS=[],
41 CXX=r'%(_python_)s myc++.py',
42 CXXFLAGS=[],
44 env.Program(target='test1', source='test1.cc')
45 env.Program(target='test2', source='test2.cpp')
46 env.Program(target='test3', source='test3.cxx')
47 env.Program(target='test4', source='test4.c++')
48 env.Program(target='test5', source='test5.C++')
49 """ % locals())
51 test.write('test1.cc', r"""This is a .cc file.
52 /*c++*/
53 #link
54 """)
56 test.write('test2.cpp', r"""This is a .cpp file.
57 /*c++*/
58 #link
59 """)
61 test.write('test3.cxx', r"""This is a .cxx file.
62 /*c++*/
63 #link
64 """)
66 test.write('test4.c++', r"""This is a .c++ file.
67 /*c++*/
68 #link
69 """)
71 test.write('test5.C++', r"""This is a .C++ file.
72 /*c++*/
73 #link
74 """)
76 test.run(arguments = '.', stderr = None)
78 test.must_match('test1' + _exe, "This is a .cc file.\n", mode='r')
80 test.must_match('test2' + _exe, "This is a .cpp file.\n", mode='r')
82 test.must_match('test3' + _exe, "This is a .cxx file.\n", mode='r')
84 test.must_match('test4' + _exe, "This is a .c++ file.\n", mode='r')
86 test.must_match('test5' + _exe, "This is a .C++ file.\n", mode='r')
88 if TestSCons.case_sensitive_suffixes('.c', '.C'):
89 test.write('SConstruct', """
90 env = Environment(
91 LINK=r'%(_python_)s mylink.py',
92 LINKFLAGS=[],
93 CXX=r'%(_python_)s myc++.py',
94 CXXFLAGS=[],
96 env.Program(target='test6', source='test6.C')
97 """ % locals())
99 test.write('test6.C', r"""This is a .C file.
100 /*c++*/
101 #link
102 """)
104 test.run(arguments = '.', stderr = None)
105 test.must_match('test6' + _exe, "This is a .C file.\n", mode='r')
107 test.file_fixture('wrapper.py')
109 test.write('SConstruct', """
110 foo = Environment()
111 cxx = foo.Dictionary('CXX')
112 bar = Environment(CXX=r'%(_python_)s wrapper.py ' + cxx)
113 foo.Program(target='foo', source='foo.cxx')
114 bar.Program(target='bar', source='bar.cxx')
115 """ % locals())
117 test.write('foo.cxx', r"""
118 #include <stdio.h>
119 #include <stdlib.h>
121 main(int argc, char *argv[])
123 argv[argc++] = (char *)"--";
124 printf("foo.cxx\n");
125 exit (0);
127 """)
129 test.write('bar.cxx', r"""
130 #include <stdio.h>
131 #include <stdlib.h>
133 main(int argc, char *argv[])
135 argv[argc++] = (char *)"--";
136 printf("foo.cxx\n");
137 exit (0);
139 """)
142 test.run(arguments = 'foo' + _exe)
144 test.must_not_exist(test.workpath('wrapper.out'))
146 test.run(arguments = 'bar' + _exe)
148 test.must_match('wrapper.out', "wrapper.py\n", mode='r')
150 test.pass_test()
152 # Local Variables:
153 # tab-width:4
154 # indent-tabs-mode:nil
155 # End:
156 # vim: set expandtab tabstop=4 shiftwidth=4: