Skip to content

Clean up the C/C++ compiler variable tests #4711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ DOCUMENTATION
DEVELOPMENT
-----------

- List visible changes in the way SCons is developed

- runtest.py once again finds "external" tests, such as the tests for
tools in scons-contrib. An earlier rework had broken this. Fixes #4699.

- Clean up C and C++ FLAGS tests. Tests which use a real compiler
are now more clearly distinguished (-live.py suffix and docstring).
- Fix a couple of unit tests to not fail with Python 3.14. These involve
expectations for bytecode and error message contents; there was no problem
with SCons itself using 3.14 in its current (just-before-freeze) state.
Expand Down
67 changes: 67 additions & 0 deletions test/CC/CC-live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
#
# 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 the C compiler name variable $CC.
This is a live test, calling the detected C compiler via a wrapper.
"""

import os
import sys
import TestSCons

_python_ = TestSCons._python_
_exe = TestSCons._exe

test = TestSCons.TestSCons()

test.dir_fixture('CC-fixture')
test.file_fixture('wrapper.py')

test.write('SConstruct', f"""\
DefaultEnvironment(tools=[])
foo = Environment()
bar = Environment()

bar['CC'] = r'{_python_} wrapper.py ' + foo['CC']
foo.Program(target='foo', source='foo.c')
bar.Program(target='bar', source='bar.c')
""")

test.run(arguments='foo' + _exe)
test.must_not_exist(test.workpath('wrapper.out'))
test.up_to_date(arguments='foo' + _exe)

test.run(arguments='bar' + _exe)
test.must_match('wrapper.out', "wrapper.py\n", mode='r')
test.up_to_date(arguments='bar' + _exe)

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
55 changes: 16 additions & 39 deletions test/CC/CC.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# 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 the C compiler name variable $CC, calling a mocked compiler.
"""

import os
import sys
import TestSCons
Expand All @@ -35,61 +39,34 @@
test.dir_fixture('CC-fixture')
test.file_fixture('mylink.py')

test.write('SConstruct', """
test.write('SConstruct', f"""\
DefaultEnvironment(tools=[])
env = Environment(
tools=['link','cc'],
LINK=r'%(_python_)s mylink.py',
tools=['link', 'cc'],
LINK=r'{_python_} mylink.py',
LINKFLAGS=[],
CC=r'%(_python_)s mycc.py',
CC=r'{_python_} mycc.py',
)
env.Program(target='test1', source='test1.c')
""" % locals())

test.run(arguments = '.', stderr = None)
""")

test.run(arguments='.', stderr=None)
test.must_match('test1' + _exe, "This is a .c file.\n", mode='r')

if os.path.normcase('.c') == os.path.normcase('.C'):

test.write('SConstruct', """
test.write('SConstruct2', f"""
DefaultEnvironment(tools=[])

env = Environment(
tools=['link','cc'],
LINK=r'%(_python_)s mylink.py',
CC=r'%(_python_)s mycc.py',
tools=['link', 'cc'],
LINK=r'{_python_} mylink.py',
CC=r'{_python_} mycc.py',
)
env.Program(target='test2', source='test2.C')
""" % locals())
""")

test.run(arguments = '.', stderr = None)
test.run(arguments=['-f', 'SConstruct2', '.'], stderr=None)
test.must_match('test2' + _exe, "This is a .C file.\n", mode='r')

test.file_fixture('wrapper.py')

test.write('SConstruct', """
DefaultEnvironment(tools=[])

foo = Environment()
bar = Environment()
bar['CC'] = r'%(_python_)s wrapper.py ' + foo['CC']
foo.Program(target='foo', source='foo.c')
bar.Program(target='bar', source='bar.c')
""" % locals())

test.run(arguments = 'foo' + _exe)

test.must_not_exist(test.workpath('wrapper.out'))

test.up_to_date(arguments = 'foo' + _exe)

test.run(arguments = 'bar' + _exe)

test.must_match('wrapper.out', "wrapper.py\n", mode='r')

test.up_to_date(arguments = 'bar' + _exe)

test.pass_test()

# Local Variables:
Expand Down
63 changes: 63 additions & 0 deletions test/CC/SHCC-live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
#
# 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 the C shared-object compiler name variable $SHCC.
This is a live test, calling the detected C compiler via a wrapper.
"""

import TestSCons

_python_ = TestSCons._python_

test = TestSCons.TestSCons()

test.file_fixture('wrapper.py')
test.file_fixture('CC-fixture/foo.c')
test.file_fixture('CC-fixture/bar.c')

test.write('SConstruct', f"""\
DefaultEnvironment(tools=[])
foo = Environment()

shcc = foo['SHCC']
bar = Environment(SHCC=r'{_python_} wrapper.py ' + shcc)
foo.SharedObject(target='foo/foo', source='foo.c')
bar.SharedObject(target='bar/bar', source='bar.c')
""")

test.run(arguments='foo')
test.must_not_exist(test.workpath('wrapper.out'))

test.run(arguments='bar')
test.must_match('wrapper.out', "wrapper.py\n", mode='r')

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
38 changes: 20 additions & 18 deletions test/CC/SHCC.py → test/CXX/CXX-live.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,59 @@
# 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 the C compiler name variable $CC.
This is a live test, calling the detected C compiler via a wrapper.
"""

import sys
import TestSCons

_python_ = TestSCons._python_
_exe = TestSCons._exe

test = TestSCons.TestSCons()

test.file_fixture('wrapper.py')

test.write('SConstruct', """
test.write('SConstruct', f"""\
DefaultEnvironment(tools=[])
foo = Environment()
shcc = foo['SHCC']
bar = Environment(SHCC = r'%(_python_)s wrapper.py ' + shcc)
foo.SharedObject(target = 'foo/foo', source = 'foo.c')
bar.SharedObject(target = 'bar/bar', source = 'bar.c')

cxx = foo.Dictionary('CXX')
bar = Environment(CXX=r'{_python_} wrapper.py ' + cxx)
foo.Program(target='foo', source='foo.cxx')
bar.Program(target='bar', source='bar.cxx')
""" % locals())

test.write('foo.c', r"""
test.write('foo.cxx', r"""
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
argv[argc++] = "--";
printf("foo.c\n");
argv[argc++] = (char *)"--";
printf("foo.cxx\n");
exit (0);
}
""")

test.write('bar.c', r"""
test.write('bar.cxx', r"""
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
argv[argc++] = "--";
printf("foo.c\n");
argv[argc++] = (char *)"--";
printf("foo.cxx\n");
exit (0);
}
""")


test.run(arguments = 'foo')

test.run(arguments='foo' + _exe)
test.must_not_exist(test.workpath('wrapper.out'))

test.run(arguments = 'bar')

test.run(arguments='bar' + _exe)
test.must_match('wrapper.out', "wrapper.py\n", mode='r')

test.pass_test()
Expand Down
Loading
Loading