Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:
with:
path: |
$HOME/.CommandBox
key: commandbox-${{ runner.os }}-${{ hashFiles('**/*.box') }}
exercises/**/testbox
key: commandbox-${{ runner.os }}-${{ hashFiles('**/box.json') }}

- name: Install CommandBox
run: |
Expand Down
109 changes: 84 additions & 25 deletions tasks/TestAllSolutions.cfc
Original file line number Diff line number Diff line change
@@ -1,27 +1,86 @@
/**
* I test all the solutions in each exercise to make sure they all pass.
*/
* I test all the example solutions to make sure they all pass.
*/
component {

function run() {
// Get an array of all the excercise names
var exercises = directoryList( expandPath( getDirectoryFromPath( getCurrentTemplatePath() ) & '../exercises' ) );
var exitCode = 0;

// If there's a testrunner task in them, run it. If any of the tasks fail, the exit code will come back as 1
exercises.each( function( path ) {
if( fileExists( path & '/TestRunner.cfc' ) ) {
command( 'task run' )
.params( 'TestRunner' )
// Specifically as the task runners to run the SolutionTest
.flags( ':solution' )
.inWorkingDirectory( path )
.run();
exitCode = max( exitCode, createObject( 'java', 'java.lang.System' ).getProperty( 'cfml.cli.exitCode' ) ?: 0 );
}
} );

setExitCode( exitCode );
}

}

function run() {
// grab concept and practice exercises
var exercisesRoot = expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & '../exercises');
var exercises = [];
for (var exerciseType in ['practice', 'concept']) {
var exerciseDir = exercisesRoot & '/' & exerciseType;
if (directoryExists(exerciseDir)) {
exercises.append(
directoryList(
exerciseDir,
false,
'path',
'',
'name',
'dir'
),
true
);
}
}
var exitCode = 0;
var count = 0;

for (var path in exercises) {
if (!fileExists(path & '/TestRunner.cfc') || !fileExists(path & '/.meta/config.json')) {
continue;
}

var slug = listLast(path, '/\');
var pascalSlug = slug
.listToArray('-')
.map(function(w) {
return w.left(1).uCase() & w.mid(2, w.len());
})
.toList('');
var stub = path & '/' & pascalSlug & '.cfc';
var example = path & '/.meta/Example.cfc';
var backup = fileRead(stub);
fileCopy(example, stub);

print.line('#slug# - running').toConsole();

// suppress output for passing tests
var passed = false;
try {
command('task run')
.params('TestRunner')
.inWorkingDirectory(path)
.run(returnOutput = true);
passed = true;
} catch (any e) {
passed = false;
}

count++;

if (passed) {
fileWrite(stub, backup);
print.line('#slug# - passed').toConsole();
} else {
// rerun without capture to get failing output
try {
command('task run')
.params('TestRunner')
.inWorkingDirectory(path)
.run();
} catch (any e) {
passed = false;
}
fileWrite(stub, backup);
exitCode = 1;
break;
}
}

print.line('Test suites run: #count#');

setExitCode(exitCode);
}

}