[SCons] Add commands for building (but not running) tests

This commit is contained in:
Ray Speth 2024-06-03 18:19:57 -04:00 committed by Ray Speth
parent cd5d7a9e34
commit 43b1fffe14
4 changed files with 15 additions and 7 deletions

View File

@ -25,6 +25,10 @@ Basic usage:
'scons test-NAME' - Run the test named "NAME".
'scons build-NAME' - Build the program for the test named "NAME".
'scons build-tests' - Build the programs for all tests.
'scons samples' - Compile the C++ and Fortran samples.
'scons msi' - Build a Windows installer (.msi) for Cantera.
@ -111,7 +115,7 @@ else:
logger.logger.setLevel("INFO")
for command in COMMAND_LINE_TARGETS:
if command not in valid_commands and not command.startswith('test'):
if command not in valid_commands and not command.startswith(('test', 'build-')):
logger.error(f"Unrecognized command line target: {command!r}")
sys.exit(1)
@ -2351,7 +2355,7 @@ if 'msi' in COMMAND_LINE_TARGETS:
build_msi = Alias('msi', msi_target)
### Tests ###
if any(target.startswith('test') for target in COMMAND_LINE_TARGETS):
if any(target.startswith(('test', 'build-')) for target in COMMAND_LINE_TARGETS):
env['testNames'] = []
env['test_results'] = env.Command('test_results', [], test_results.print_report)

View File

@ -339,7 +339,7 @@ of the GTest test suite by changing the `program` name above.
Before running any of the GTest programs through VS Code, you will first need to
use SCons to compile the corresponding test program, for example by running
```sh
scons test-thermo
scons build-thermo
```
If you make any changes to the test program or the Cantera library code, re-run this
@ -360,11 +360,11 @@ help with running either the C++ or Python tests through GDB on Linux.
### Running C++ (GoogleTest) Tests
First, run the target test through SCons to make sure the Cantera library and the test
First, build the target test through SCons to make sure the Cantera library and the test
executable are up to date. We'll use the `kinetics` test subset as an example, with the
goal of debugging the `PlogLowPressure` test.
```sh
scons test-kinetics
scons build-kinetics
```
Next, you need to set some environment variables that specify where the test program can

View File

@ -104,7 +104,9 @@ def addTestProgram(subdir, progName, env_vars={}):
run_program = testenv.Command(passedFile, program, gtestRunner)
env.Depends(run_program, env['build_targets'])
env.Depends(env['test_results'], run_program)
Alias('test-%s' % progName, run_program)
Alias(f'test-{progName}', run_program)
Alias(f'build-{progName}', program)
Alias('build-tests', program)
env['testNames'].append(progName)
else:
test_results.failed['test-%s (googletest disabled)' % progName] = 1

View File

@ -71,7 +71,9 @@ class Test(object):
localenv.Depends(env['test_results'], run)
localenv.Depends(run, env['build_targets'])
localenv.Alias('test-clean', self.clean(localenv))
localenv.Alias('test-%s' % self.testName, run)
localenv.Alias(f'test-{self.testName}', run)
localenv.Alias(f'build-{self.testName}', self.program)
localenv.Alias('build-tests', self.program)
env['testNames'].append(self.testName)
# reset: just delete the ".passed" file so that this test will be re-run