diff --git a/.gitignore b/.gitignore index 3e95081..2761537 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ tests/**/results.json -tests/**/testbox/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3b3717e..f15ab95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ -FROM ortussolutions/commandbox:jdk11-3.9.3 +FROM ortussolutions/boxlang:cli-alpine-1.11.0 WORKDIR /opt/test-runner -# Pre-install box dependencies for offline usage -COPY box.json . -RUN box install +# Pre-install testbox and its dependencies for offline usage +RUN bash /usr/local/boxlang/scripts/install-bx-module.sh testbox \ + && bash /usr/local/boxlang/scripts/install-bx-module.sh globber \ + && mkdir -p ~/.boxlang/modules/testbox/system/modules \ + && cp -R ~/.boxlang/modules/globber ~/.boxlang/modules/testbox/system/modules/ COPY . . diff --git a/bin/run-tests.sh b/bin/run-tests.sh index b77cb00..e627da8 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -1,7 +1,8 @@ -#! /bin/sh +#!/usr/bin/env bash +set -euo pipefail # Synopsis: -# Test the test runner by running it against a predefined set of solutions +# Test the test runner by running it against a predefined set of solutions # with an expected output. # Output: @@ -15,26 +16,19 @@ exit_code=0 # Iterate over all test directories for test_dir in tests/*; do - test_dir_name=$(basename "${test_dir}") - test_dir_path=$(realpath "${test_dir}") - results_file_path="${test_dir_path}/results.json" - expected_results_file_path="${test_dir_path}/expected_results.json" - - bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - - # Normalize the results file - sed -i -E \ - -e 's/\s+\([0-9]+ ms\)//g' \ - -e 's/Duration.*[0-9]+ms//g' \ - -e "s~${test_dir_path}~/solution~g" \ - "${results_file_path}" - - echo "${test_dir_name}: comparing results.json to expected_results.json" - diff "${results_file_path}" "${expected_results_file_path}" - - if [ $? -ne 0 ]; then - exit_code=1 - fi + test_dir_name="${test_dir##*/}" + test_dir_path="$(realpath "${test_dir}")" + results_file_path="${test_dir_path}/results.json" + expected_results_file_path="${test_dir_path}/expected_results.json" + + bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" + + echo "${test_dir_name}: comparing results.json to expected_results.json" + diff "${results_file_path}" "${expected_results_file_path}" + + if [ $? -ne 0 ]; then + exit_code=1 + fi done exit ${exit_code} diff --git a/bin/run.sh b/bin/run.sh index cd82c1a..a0a523e 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -5,60 +5,51 @@ # Arguments: # $1: exercise slug -# $2: absolute path to solution folder -# $3: absolute path to output directory +# $2: path to solution folder +# $3: path to output directory # Output: # Writes the test results to a results.json file in the passed-in output directory. # The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md # Example: -# ./bin/run.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/ +# ./bin/run.sh two-fer path/to/solution/folder/ path/to/output/directory/ -# If any required arguments is missing, print the usage and exit -if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "usage: ./bin/run.sh exercise-slug /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/" - exit 1 +set -euo pipefail + +# If any required argument is missing, print the usage and exit +if [[ -z "$1" || -z "$2" || -z "$3" ]]; then + echo "usage: ./bin/run.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" + exit 1 fi slug="$1" input_dir="${2%/}" output_dir="${3%/}" -exercise="${slug//-/_}" -implementation_file="${input_dir}/${exercise}.pl" -tests_file="${input_dir}/${exercise}_tests.plt" results_file="${output_dir}/results.json" -# Create the output directory if it doesn't exist -mkdir -p "${output_dir}" +if ! mkdir -p "${output_dir}"; then + jq -n '{"version": 2, "status": "error", "message": "The test runner failed to create the output directory for your test run. Please open a thread on the Exercism forums."}' > "${results_file}" + exit 1 +fi echo "${slug}: testing..." -pushd "${input_dir}" > /dev/null +script_dir="${0%/*}" -# Run the tests for the provided implementation file and redirect stdout and -# stderr to capture it -test_output=$(box task run TestRunner 2>&1) -exit_code=$? +# Avoid JVM DNS lookup issue on Alpine +echo "127.0.0.1 $HOSTNAME" > /tmp/hosts +export JAVA_TOOL_OPTIONS="-Djdk.net.hosts.file=/tmp/hosts" -popd > /dev/null +# Need a writable home directory +export BOXLANG_HOME=/tmp/.boxlang -# Write the results.json file based on the exit code of the command that was -# just executed that tested the implementation file -if [ $exit_code -eq 0 ]; then - jq -n '{version: 1, status: "pass"}' > ${results_file} -else - # Sanitize the test output - sanitized_test_output=$(echo "${test_output}" \ - | sed -E 's/.*(Installing package|Installing.+dependencies).*//g' \ - | sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}') +boxlang "${script_dir}/test-runner.bxs" "${input_dir}" "${output_dir}" > /dev/null 2>&1 || true - # Manually add colors to the output to help scanning the output for errors - colorized_test_output=$(echo "${sanitized_test_output}" \ - | GREP_COLOR='01;31' grep --color=always -E -e 'X.*\([0-9]+ ms\)|$' -e '-> Failure.*|$' \ - | GREP_COLOR='01;32' grep --color=always -E -e '√.*\([0-9]+ ms\)|$') - - jq -n --arg output "${colorized_test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file} +if [[ ! -f "${results_file}" ]]; then + jq -n '{"version": 2, "status": "error", "message": "The test runner failed to run your tests. Please open a thread on the Exercism forums."}' > "${results_file}" fi +jq . "${results_file}" > "${results_file}.tmp" && mv "${results_file}.tmp" "${results_file}" + echo "${slug}: done" diff --git a/bin/test-runner.bxs b/bin/test-runner.bxs new file mode 100644 index 0000000..0caa0b5 --- /dev/null +++ b/bin/test-runner.bxs @@ -0,0 +1,112 @@ +solutionPath = server.cli.parsed.positionals[ 1 ]; +resultsPath = server.cli.parsed.positionals[ 2 ]; + +try { + userHome = server.system.properties[ "user.home" ]; + mappings = getApplicationMetadata().mappings; + mappings[ "/solution" ] = solutionPath; + mappings[ "/testbox" ] = userHome & "/.boxlang/modules/testbox"; + + testBox = new testbox.system.TestBox(); + testFiles = directoryList( solutionPath, false, "name", "*Test.cfc" ); + for ( file in testFiles ) { + testBox.addBundles( "solution." & file.listFirst( "." ) ); + } + + results = testBox.runRaw().getMemento(); + bundleStats = results.bundleStats ?: []; + + status = "pass"; + message = ""; + tests = []; + + for ( bundle in bundleStats ) { + if ( structKeyExists( bundle, "globalException" ) && !isSimpleValue( bundle.globalException ) ) { + status = "error"; + message = ( bundle.globalException.message ?: "Bundle compilation error" ).replace( solutionPath, "/solution", "ALL" ); + break; + } + } + + if ( status != "error" ) { + if ( ( results.totalBundles ?: 0 ) == 0 ) { + status = "error"; + message = "No tests found"; + } else { + // Read test file contents + for ( bundle in bundleStats ) { + testFileName = bundle.name.listLast( "." ) & ".cfc"; + filePath = solutionPath & "/" & testFileName; + fileContent = fileExists( filePath ) ? fileRead( filePath ) : ""; + collectSpecs( bundle.suiteStats ?: [], tests, fileContent ); + } + if ( ( results.totalFail ?: 0 ) > 0 || ( results.totalError ?: 0 ) > 0 ) { + status = "fail"; + } + } + } + + output = { "version": 2, "status": status }; + if ( message.len() ) { + output[ "message" ] = message; + } + if ( tests.len() ) { + output[ "tests" ] = tests; + } + + fileWrite( resultsPath & "/results.json", jsonSerialize( output ) ); + +} catch ( any e ) { + errMessage = e.message.replace( solutionPath, "/solution", "ALL" ); + fileWrite( resultsPath & "/results.json", + jsonSerialize( { "version": 2, "status": "error", "message": errMessage } ) ); +} + +// Recursively collect specs +function collectSpecs( required array suites, required array tests, required string fileContent ) { + for ( var suite in suites ) { + for ( var spec in ( suite.specStats ?: [] ) ) { + var specStatus = ( spec.status ?: "failed" ).lCase(); + var testResult = { + "name": spec.name ?: "Unknown", + "status": specStatus == "passed" ? "pass" : ( specStatus == "failed" ? "fail" : "error" ), + "test_code": extractTestCode( fileContent, spec.name ?: "" ) + }; + if ( testResult.status != "pass" && ( spec.failMessage ?: "" ).len() ) { + testResult[ "message" ] = spec.failMessage; + } + tests.append( testResult ); + } + if ( structKeyExists( suite, "suiteStats" ) && suite.suiteStats.len() ) { + collectSpecs( suite.suiteStats, tests, fileContent ); + } + } +} + +// Extract the body of an it() block +function extractTestCode( required string fileContent, required string testName ) { + if ( !fileContent.len() || !testName.len() ) return ""; + + var lines = fileContent.listToArray( char( 10 ) ); + var depth = 1; + var found = false; + var body = []; + + for ( var line in lines ) { + if ( !found ) { + if ( line.reFind( "it\(\s*['""]" & testName & "['""]" ) > 0 && line.find( "{" ) > 0 ) { + found = true; + } + continue; + } + + for ( var ch in line.listToArray( "" ) ) { + if ( ch == "{" ) depth++; + if ( ch == "}" ) depth--; + } + if ( depth <= 0 ) break; + body.append( line ); + } + + return trim( body.toList( char( 10 ) ) ); +} diff --git a/box.json b/box.json deleted file mode 100644 index 4e5af44..0000000 --- a/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-empty-file/Leap.cfc b/tests/error-if-empty-file/ErrorIfEmptyFile.cfc similarity index 100% rename from tests/example-empty-file/Leap.cfc rename to tests/error-if-empty-file/ErrorIfEmptyFile.cfc diff --git a/tests/error-if-empty-file/ErrorIfEmptyFileTest.cfc b/tests/error-if-empty-file/ErrorIfEmptyFileTest.cfc new file mode 100644 index 0000000..e1986fd --- /dev/null +++ b/tests/error-if-empty-file/ErrorIfEmptyFileTest.cfc @@ -0,0 +1,19 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'ErrorIfEmptyFile' ); + } + + function run(){ + + describe( 'ErrorIfEmptyFile', function(){ + + it( 'This should error', function(){ + expect( SUT.alwaysTrue() ).toBeTrue(); + }); + + }); + + } + +} diff --git a/tests/error-if-empty-file/expected_results.json b/tests/error-if-empty-file/expected_results.json new file mode 100644 index 0000000..7fbb2de --- /dev/null +++ b/tests/error-if-empty-file/expected_results.json @@ -0,0 +1,5 @@ +{ + "message": "Error compiling [ /solution/ErrorIfEmptyFile.cfc ]. /solution/ErrorIfEmptyFile.cfc: Line: 1 Col: 0 - '' was unexpected \nexpecting one of: 'abstract', 'final', Operator, Statement\n\n", + "version": 2, + "status": "error" +} diff --git a/tests/error-if-syntax-error/ErrorIfSyntaxError.cfc b/tests/error-if-syntax-error/ErrorIfSyntaxError.cfc new file mode 100644 index 0000000..53f03ea --- /dev/null +++ b/tests/error-if-syntax-error/ErrorIfSyntaxError.cfc @@ -0,0 +1 @@ +componentTTT@@ clazzzz diff --git a/tests/error-if-syntax-error/ErrorIfSyntaxErrorTest.cfc b/tests/error-if-syntax-error/ErrorIfSyntaxErrorTest.cfc new file mode 100644 index 0000000..ef4de60 --- /dev/null +++ b/tests/error-if-syntax-error/ErrorIfSyntaxErrorTest.cfc @@ -0,0 +1,19 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'ErrorIfSyntaxError' ); + } + + function run(){ + + describe( 'ErrorIfSyntaxError', function(){ + + it( 'This will error out', function(){ + expect( SUT.alwaysTrue() ).toBeTrue(); + }); + + }); + + } + +} diff --git a/tests/error-if-syntax-error/expected_results.json b/tests/error-if-syntax-error/expected_results.json new file mode 100644 index 0000000..43dfc1f --- /dev/null +++ b/tests/error-if-syntax-error/expected_results.json @@ -0,0 +1,5 @@ +{ + "message": "Error compiling [ /solution/ErrorIfSyntaxError.cfc ]. /solution/ErrorIfSyntaxError.cfc: Line: 1 Col: 0 - 'componentTTT' was unexpected \nexpecting one of: 'abstract', 'final', Operator, Statement\ncomponentTTT@@ clazzzz\n^^^^^^^^^^^^", + "version": 2, + "status": "error" +} diff --git a/tests/example-all-fail/Leap.cfc b/tests/example-all-fail/Leap.cfc deleted file mode 100644 index 0ccaf5b..0000000 --- a/tests/example-all-fail/Leap.cfc +++ /dev/null @@ -1,14 +0,0 @@ -/** -* Here is an example solution for the Leap exercise -*/ -component { - - /** - * @year The input year to consider - * - * @returns A boolean for whether the inputted year is true or false - */ - function leapYear( year ) { - return year % 2 == 1; - } -} \ No newline at end of file diff --git a/tests/example-all-fail/TestRunner.cfc b/tests/example-all-fail/TestRunner.cfc deleted file mode 100644 index c870f90..0000000 --- a/tests/example-all-fail/TestRunner.cfc +++ /dev/null @@ -1,103 +0,0 @@ -/** -* I am a CommandBox task runner which you can use to test your implementation of this exercise against the -* provided test suite. To use me, open the CommandBox CLI and run this: -* -* CommandBox> task run TestRunner -* -* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: -* -* CommandBox> task run TestRunner --watcher -* -*/ -component { - - /** - * @solution Runs the tests against the solution - * @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop - */ - function run( boolean solution=false, boolean watcher=false ) { - - ensureTestBox(); - - if( watcher ) { - - // Tabula rasa - command( 'cls' ).run(); - - // Start watcher - watch() - .paths( '*.cfc' ) - .inDirectory( getCWD() ) - .withDelay( 500 ) - .onChange( function() { - - // Clear the screen - command( 'cls' ) - .run(); - - // This is neccessary so changes to tests get picked up right away. - pagePoolClear(); - - runTests( solution ); - - } ) - .start(); - - } else { - runTests( solution ); - } - - } - - /** - * Make sure the TestBox framework is installed - */ - private function ensureTestBox() { - var excerciseRoot = getCWD(); - var testBoxRoot = excerciseRoot & '/testbox'; - - if( !directoryExists( testBoxRoot ) ) { - - print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); - command( 'install' ) - .inWorkingDirectory( excerciseRoot ) - .run(); - } - - // Bootstrap TestBox framework - filesystemUtil.createMapping( '/testbox', testBoxRoot ); - } - - /** - * Invoke TestBox to run the test suite - */ - private function runTests( boolean solution=false ) { - - // Create TestBox and run the tests - testData = new testbox.system.TestBox() - .runRaw( directory = { - // Find all CFCs... - mapping = filesystemUtil.makePathRelative( getCWD() ), - // ... in this directory ... - recurse = false, - // ... whose name ends in "test" - filter = function( path ) { - return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); - } - } ) - .getMemento(); - - // Print out the results with ANSI formatting for the CLI - getInstance( 'CLIRenderer@testbox-cli' ) - .render( print, testData, true ); - - print.toConsole(); - - // Set proper exit code - if( testData.totalFail || testData.totalError ) { - setExitCode( 1 ); - } - } - -} - diff --git a/tests/example-all-fail/box.json b/tests/example-all-fail/box.json deleted file mode 100644 index 4e5af44..0000000 --- a/tests/example-all-fail/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-all-fail/expected_results.json b/tests/example-all-fail/expected_results.json deleted file mode 100644 index b6f538a..0000000 --- a/tests/example-all-fail/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "!! opt.test-runner.tests.example-all-fail.LeapTest\n[Passed: 0] [Failed: 2] [Errors: 0] [Skipped: 0] [Suites/Specs: 1/2]\n\n X My Leap class \r\n \u001b[01;31m\u001b[KX year not divisible by 4: common year\u001b[m\u001b[K \r\n \u001b[01;31m\u001b[K-> Failure: Expected [true] to be false\r\u001b[m\u001b[K\n \u001b[01;31m\u001b[KX year divisible by 4, not divisible by 100: leap year\u001b[m\u001b[K \r\n \u001b[01;31m\u001b[K-> Failure: Expected [false] to be true\r\u001b[m\u001b[K\n\n╔═════════════════════════════════════════════════════════════════════╗\n║ Passed ║ Failed ║ Errored ║ Skipped ║ Bundles ║ Suites ║ Specs ║\n╠═════════════════════════════════════════════════════════════════════╣\n║ 0 ║ 2 ║ 0 ║ 0 ║ 1 ║ 1 ║ 2 ║\n╚═════════════════════════════════════════════════════════════════════╝\n\nTestBox \tv2.8.0+191\nCFML Engine\t\n\nLabels \t\t---\n\n√ Passed - Skipped !! Exception/Error X Failure\n\n\n\n\u001b[38;5;15m\u001b[48;5;9mERROR (6.0.0+00787)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mTask returned failing exit code (1)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mFailing Task: /solution/TestRunner.cfc run\u001b[0m" -} diff --git a/tests/example-all-fail/index.cfm b/tests/example-all-fail/index.cfm deleted file mode 100644 index 1e35079..0000000 --- a/tests/example-all-fail/index.cfm +++ /dev/null @@ -1,37 +0,0 @@ - - - - - // get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" - // And turn it into compnent path relative to the web root - url.bundles = directoryList( - path=expandPath( '/' ), - filter='*Test.cfc' ) - .map( function( path ) { - return path - .replaceNoCase( expandPath( '/' ), '' ) - .left( -4 ) - } ) - .toList(); - - - - - - - - Oops, you don't have TestBox installed yet! Please run box install from the root of your excercise folder and refresh this page. - diff --git a/tests/example-empty-file/LeapTest.cfc b/tests/example-empty-file/LeapTest.cfc deleted file mode 100644 index e6e786a..0000000 --- a/tests/example-empty-file/LeapTest.cfc +++ /dev/null @@ -1,31 +0,0 @@ -component extends="testbox.system.BaseSpec" { - - function beforeAll(){ - SUT = createObject( 'Leap' ); - } - - function run(){ - - describe( "My Leap class", function(){ - - it( 'year not divisible by 4: common year', function(){ - expect( SUT.leapYear( year='2015' ) ).toBeFalse(); - }); - - it( 'year divisible by 4, not divisible by 100: leap year', function(){ - expect( SUT.leapYear( year='1996' ) ).toBeTrue(); - }); - - it( 'year divisible by 100, not divisible by 400: common year', function(){ - expect( SUT.leapYear( year='2100' ) ).toBeFalse(); - }); - - it( 'year divisible by 400: leap year', function(){ - expect( SUT.leapYear( year='2000' ) ).toBeTrue(); - }); - - }); - - } - -} \ No newline at end of file diff --git a/tests/example-empty-file/TestRunner.cfc b/tests/example-empty-file/TestRunner.cfc deleted file mode 100644 index c870f90..0000000 --- a/tests/example-empty-file/TestRunner.cfc +++ /dev/null @@ -1,103 +0,0 @@ -/** -* I am a CommandBox task runner which you can use to test your implementation of this exercise against the -* provided test suite. To use me, open the CommandBox CLI and run this: -* -* CommandBox> task run TestRunner -* -* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: -* -* CommandBox> task run TestRunner --watcher -* -*/ -component { - - /** - * @solution Runs the tests against the solution - * @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop - */ - function run( boolean solution=false, boolean watcher=false ) { - - ensureTestBox(); - - if( watcher ) { - - // Tabula rasa - command( 'cls' ).run(); - - // Start watcher - watch() - .paths( '*.cfc' ) - .inDirectory( getCWD() ) - .withDelay( 500 ) - .onChange( function() { - - // Clear the screen - command( 'cls' ) - .run(); - - // This is neccessary so changes to tests get picked up right away. - pagePoolClear(); - - runTests( solution ); - - } ) - .start(); - - } else { - runTests( solution ); - } - - } - - /** - * Make sure the TestBox framework is installed - */ - private function ensureTestBox() { - var excerciseRoot = getCWD(); - var testBoxRoot = excerciseRoot & '/testbox'; - - if( !directoryExists( testBoxRoot ) ) { - - print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); - command( 'install' ) - .inWorkingDirectory( excerciseRoot ) - .run(); - } - - // Bootstrap TestBox framework - filesystemUtil.createMapping( '/testbox', testBoxRoot ); - } - - /** - * Invoke TestBox to run the test suite - */ - private function runTests( boolean solution=false ) { - - // Create TestBox and run the tests - testData = new testbox.system.TestBox() - .runRaw( directory = { - // Find all CFCs... - mapping = filesystemUtil.makePathRelative( getCWD() ), - // ... in this directory ... - recurse = false, - // ... whose name ends in "test" - filter = function( path ) { - return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); - } - } ) - .getMemento(); - - // Print out the results with ANSI formatting for the CLI - getInstance( 'CLIRenderer@testbox-cli' ) - .render( print, testData, true ); - - print.toConsole(); - - // Set proper exit code - if( testData.totalFail || testData.totalError ) { - setExitCode( 1 ); - } - } - -} - diff --git a/tests/example-empty-file/box.json b/tests/example-empty-file/box.json deleted file mode 100644 index 4e5af44..0000000 --- a/tests/example-empty-file/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-empty-file/expected_results.json b/tests/example-empty-file/expected_results.json deleted file mode 100644 index 498137f..0000000 --- a/tests/example-empty-file/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "- opt.test-runner.tests.example-empty-file.LeapTest\n[Passed: 0] [Failed: 0] [Errors: 7] [Skipped: 0] [Suites/Specs: 0/0]\n\nGLOBAL BUNDLE EXCEPTION\n-> template:template [/solution/Leap.cfc] must contain a component or an interface.:\n-> at /solution/Leap.cfc:2 \r\r\n\n\n-> at /solution/LeapTest.cfc:4 \r\r\n-> at /solution/testbox/system/runners/BDDRunner.cfc:58 \r\r\n-> at /solution/testbox/system/TestBox.cfc:461 \r\r\n-> at /solution/testbox/system/TestBox.cfc:243 \r\r\n---------------------------------------------------------------------------------\n\n╔═════════════════════════════════════════════════════════════════════╗\n║ Passed ║ Failed ║ Errored ║ Skipped ║ Bundles ║ Suites ║ Specs ║\n╠═════════════════════════════════════════════════════════════════════╣\n║ 0 ║ 0 ║ 7 ║ 0 ║ 1 ║ 0 ║ 0 ║\n╚═════════════════════════════════════════════════════════════════════╝\n\nTestBox \tv2.8.0+191\nCFML Engine\t\n\nLabels \t\t---\n√ Passed - Skipped !! Exception/Error X Failure\n\n\n\n\u001b[38;5;15m\u001b[48;5;9mERROR (6.0.0+00787)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mTask returned failing exit code (1)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mFailing Task: /solution/TestRunner.cfc run\u001b[0m" -} diff --git a/tests/example-empty-file/index.cfm b/tests/example-empty-file/index.cfm deleted file mode 100644 index 1e35079..0000000 --- a/tests/example-empty-file/index.cfm +++ /dev/null @@ -1,37 +0,0 @@ - - - - - // get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" - // And turn it into compnent path relative to the web root - url.bundles = directoryList( - path=expandPath( '/' ), - filter='*Test.cfc' ) - .map( function( path ) { - return path - .replaceNoCase( expandPath( '/' ), '' ) - .left( -4 ) - } ) - .toList(); - - - - - - - - Oops, you don't have TestBox installed yet! Please run box install from the root of your excercise folder and refresh this page. - diff --git a/tests/example-partial-fail/Leap.cfc b/tests/example-partial-fail/Leap.cfc deleted file mode 100644 index 52a1d5c..0000000 --- a/tests/example-partial-fail/Leap.cfc +++ /dev/null @@ -1,19 +0,0 @@ -/** -* Here is an example solution for the Leap exercise -*/ -component { - - /** - * @year The input year to consider - * - * @returns A boolean for whether the inputted year is true or false - */ - function leapYear( year ) { - if( year % 401 == 0 ) { - return true; - } else if( year % 4 == 0 && year % 100 != 0 ) { - return true; - } - return false; - } -} \ No newline at end of file diff --git a/tests/example-partial-fail/LeapTest.cfc b/tests/example-partial-fail/LeapTest.cfc deleted file mode 100644 index e6e786a..0000000 --- a/tests/example-partial-fail/LeapTest.cfc +++ /dev/null @@ -1,31 +0,0 @@ -component extends="testbox.system.BaseSpec" { - - function beforeAll(){ - SUT = createObject( 'Leap' ); - } - - function run(){ - - describe( "My Leap class", function(){ - - it( 'year not divisible by 4: common year', function(){ - expect( SUT.leapYear( year='2015' ) ).toBeFalse(); - }); - - it( 'year divisible by 4, not divisible by 100: leap year', function(){ - expect( SUT.leapYear( year='1996' ) ).toBeTrue(); - }); - - it( 'year divisible by 100, not divisible by 400: common year', function(){ - expect( SUT.leapYear( year='2100' ) ).toBeFalse(); - }); - - it( 'year divisible by 400: leap year', function(){ - expect( SUT.leapYear( year='2000' ) ).toBeTrue(); - }); - - }); - - } - -} \ No newline at end of file diff --git a/tests/example-partial-fail/TestRunner.cfc b/tests/example-partial-fail/TestRunner.cfc deleted file mode 100644 index c870f90..0000000 --- a/tests/example-partial-fail/TestRunner.cfc +++ /dev/null @@ -1,103 +0,0 @@ -/** -* I am a CommandBox task runner which you can use to test your implementation of this exercise against the -* provided test suite. To use me, open the CommandBox CLI and run this: -* -* CommandBox> task run TestRunner -* -* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: -* -* CommandBox> task run TestRunner --watcher -* -*/ -component { - - /** - * @solution Runs the tests against the solution - * @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop - */ - function run( boolean solution=false, boolean watcher=false ) { - - ensureTestBox(); - - if( watcher ) { - - // Tabula rasa - command( 'cls' ).run(); - - // Start watcher - watch() - .paths( '*.cfc' ) - .inDirectory( getCWD() ) - .withDelay( 500 ) - .onChange( function() { - - // Clear the screen - command( 'cls' ) - .run(); - - // This is neccessary so changes to tests get picked up right away. - pagePoolClear(); - - runTests( solution ); - - } ) - .start(); - - } else { - runTests( solution ); - } - - } - - /** - * Make sure the TestBox framework is installed - */ - private function ensureTestBox() { - var excerciseRoot = getCWD(); - var testBoxRoot = excerciseRoot & '/testbox'; - - if( !directoryExists( testBoxRoot ) ) { - - print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); - command( 'install' ) - .inWorkingDirectory( excerciseRoot ) - .run(); - } - - // Bootstrap TestBox framework - filesystemUtil.createMapping( '/testbox', testBoxRoot ); - } - - /** - * Invoke TestBox to run the test suite - */ - private function runTests( boolean solution=false ) { - - // Create TestBox and run the tests - testData = new testbox.system.TestBox() - .runRaw( directory = { - // Find all CFCs... - mapping = filesystemUtil.makePathRelative( getCWD() ), - // ... in this directory ... - recurse = false, - // ... whose name ends in "test" - filter = function( path ) { - return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); - } - } ) - .getMemento(); - - // Print out the results with ANSI formatting for the CLI - getInstance( 'CLIRenderer@testbox-cli' ) - .render( print, testData, true ); - - print.toConsole(); - - // Set proper exit code - if( testData.totalFail || testData.totalError ) { - setExitCode( 1 ); - } - } - -} - diff --git a/tests/example-partial-fail/box.json b/tests/example-partial-fail/box.json deleted file mode 100644 index 4e5af44..0000000 --- a/tests/example-partial-fail/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-partial-fail/expected_results.json b/tests/example-partial-fail/expected_results.json deleted file mode 100644 index 67b19e6..0000000 --- a/tests/example-partial-fail/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "!! opt.test-runner.tests.example-partial-fail.LeapTest\n[Passed: 3] [Failed: 1] [Errors: 0] [Skipped: 0] [Suites/Specs: 1/4]\n\n X My Leap class \r\n \u001b[01;32m\u001b[K√ year not divisible by 4: common year\u001b[m\u001b[K \r\n \u001b[01;32m\u001b[K√ year divisible by 4, not divisible by 100: leap year\u001b[m\u001b[K \r\n \u001b[01;32m\u001b[K√ year divisible by 100, not divisible by 400: common year\u001b[m\u001b[K \r\n \u001b[01;31m\u001b[KX year divisible by 400: leap year\u001b[m\u001b[K \r\n \u001b[01;31m\u001b[K-> Failure: Expected [false] to be true\r\u001b[m\u001b[K\n\n╔═════════════════════════════════════════════════════════════════════╗\n║ Passed ║ Failed ║ Errored ║ Skipped ║ Bundles ║ Suites ║ Specs ║\n╠═════════════════════════════════════════════════════════════════════╣\n║ 3 ║ 1 ║ 0 ║ 0 ║ 1 ║ 1 ║ 4 ║\n╚═════════════════════════════════════════════════════════════════════╝\n\nTestBox \tv2.8.0+191\nCFML Engine\t\n\nLabels \t\t---\n\n√ Passed - Skipped !! Exception/Error X Failure\n\n\n\n\u001b[38;5;15m\u001b[48;5;9mERROR (6.0.0+00787)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mTask returned failing exit code (1)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mFailing Task: /solution/TestRunner.cfc run\u001b[0m" -} diff --git a/tests/example-partial-fail/index.cfm b/tests/example-partial-fail/index.cfm deleted file mode 100644 index 1e35079..0000000 --- a/tests/example-partial-fail/index.cfm +++ /dev/null @@ -1,37 +0,0 @@ - - - - - // get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" - // And turn it into compnent path relative to the web root - url.bundles = directoryList( - path=expandPath( '/' ), - filter='*Test.cfc' ) - .map( function( path ) { - return path - .replaceNoCase( expandPath( '/' ), '' ) - .left( -4 ) - } ) - .toList(); - - - - - - - - Oops, you don't have TestBox installed yet! Please run box install from the root of your excercise folder and refresh this page. - diff --git a/tests/example-success/LeapTest.cfc b/tests/example-success/LeapTest.cfc deleted file mode 100644 index e6e786a..0000000 --- a/tests/example-success/LeapTest.cfc +++ /dev/null @@ -1,31 +0,0 @@ -component extends="testbox.system.BaseSpec" { - - function beforeAll(){ - SUT = createObject( 'Leap' ); - } - - function run(){ - - describe( "My Leap class", function(){ - - it( 'year not divisible by 4: common year', function(){ - expect( SUT.leapYear( year='2015' ) ).toBeFalse(); - }); - - it( 'year divisible by 4, not divisible by 100: leap year', function(){ - expect( SUT.leapYear( year='1996' ) ).toBeTrue(); - }); - - it( 'year divisible by 100, not divisible by 400: common year', function(){ - expect( SUT.leapYear( year='2100' ) ).toBeFalse(); - }); - - it( 'year divisible by 400: leap year', function(){ - expect( SUT.leapYear( year='2000' ) ).toBeTrue(); - }); - - }); - - } - -} \ No newline at end of file diff --git a/tests/example-success/TestRunner.cfc b/tests/example-success/TestRunner.cfc deleted file mode 100644 index c870f90..0000000 --- a/tests/example-success/TestRunner.cfc +++ /dev/null @@ -1,103 +0,0 @@ -/** -* I am a CommandBox task runner which you can use to test your implementation of this exercise against the -* provided test suite. To use me, open the CommandBox CLI and run this: -* -* CommandBox> task run TestRunner -* -* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: -* -* CommandBox> task run TestRunner --watcher -* -*/ -component { - - /** - * @solution Runs the tests against the solution - * @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop - */ - function run( boolean solution=false, boolean watcher=false ) { - - ensureTestBox(); - - if( watcher ) { - - // Tabula rasa - command( 'cls' ).run(); - - // Start watcher - watch() - .paths( '*.cfc' ) - .inDirectory( getCWD() ) - .withDelay( 500 ) - .onChange( function() { - - // Clear the screen - command( 'cls' ) - .run(); - - // This is neccessary so changes to tests get picked up right away. - pagePoolClear(); - - runTests( solution ); - - } ) - .start(); - - } else { - runTests( solution ); - } - - } - - /** - * Make sure the TestBox framework is installed - */ - private function ensureTestBox() { - var excerciseRoot = getCWD(); - var testBoxRoot = excerciseRoot & '/testbox'; - - if( !directoryExists( testBoxRoot ) ) { - - print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); - command( 'install' ) - .inWorkingDirectory( excerciseRoot ) - .run(); - } - - // Bootstrap TestBox framework - filesystemUtil.createMapping( '/testbox', testBoxRoot ); - } - - /** - * Invoke TestBox to run the test suite - */ - private function runTests( boolean solution=false ) { - - // Create TestBox and run the tests - testData = new testbox.system.TestBox() - .runRaw( directory = { - // Find all CFCs... - mapping = filesystemUtil.makePathRelative( getCWD() ), - // ... in this directory ... - recurse = false, - // ... whose name ends in "test" - filter = function( path ) { - return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); - } - } ) - .getMemento(); - - // Print out the results with ANSI formatting for the CLI - getInstance( 'CLIRenderer@testbox-cli' ) - .render( print, testData, true ); - - print.toConsole(); - - // Set proper exit code - if( testData.totalFail || testData.totalError ) { - setExitCode( 1 ); - } - } - -} - diff --git a/tests/example-success/box.json b/tests/example-success/box.json deleted file mode 100644 index 65002e2..0000000 --- a/tests/example-success/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-success/expected_results.json b/tests/example-success/expected_results.json deleted file mode 100644 index 6c2223e..0000000 --- a/tests/example-success/expected_results.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version": 1, - "status": "pass" -} diff --git a/tests/example-success/index.cfm b/tests/example-success/index.cfm deleted file mode 100644 index 1e35079..0000000 --- a/tests/example-success/index.cfm +++ /dev/null @@ -1,37 +0,0 @@ - - - - - // get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" - // And turn it into compnent path relative to the web root - url.bundles = directoryList( - path=expandPath( '/' ), - filter='*Test.cfc' ) - .map( function( path ) { - return path - .replaceNoCase( expandPath( '/' ), '' ) - .left( -4 ) - } ) - .toList(); - - - - - - - - Oops, you don't have TestBox installed yet! Please run box install from the root of your excercise folder and refresh this page. - diff --git a/tests/example-syntax-error/Leap.cfc b/tests/example-syntax-error/Leap.cfc deleted file mode 100644 index 5437f5b..0000000 --- a/tests/example-syntax-error/Leap.cfc +++ /dev/null @@ -1 +0,0 @@ -componentTTT@@ clazzzz \ No newline at end of file diff --git a/tests/example-syntax-error/LeapTest.cfc b/tests/example-syntax-error/LeapTest.cfc deleted file mode 100644 index e6e786a..0000000 --- a/tests/example-syntax-error/LeapTest.cfc +++ /dev/null @@ -1,31 +0,0 @@ -component extends="testbox.system.BaseSpec" { - - function beforeAll(){ - SUT = createObject( 'Leap' ); - } - - function run(){ - - describe( "My Leap class", function(){ - - it( 'year not divisible by 4: common year', function(){ - expect( SUT.leapYear( year='2015' ) ).toBeFalse(); - }); - - it( 'year divisible by 4, not divisible by 100: leap year', function(){ - expect( SUT.leapYear( year='1996' ) ).toBeTrue(); - }); - - it( 'year divisible by 100, not divisible by 400: common year', function(){ - expect( SUT.leapYear( year='2100' ) ).toBeFalse(); - }); - - it( 'year divisible by 400: leap year', function(){ - expect( SUT.leapYear( year='2000' ) ).toBeTrue(); - }); - - }); - - } - -} \ No newline at end of file diff --git a/tests/example-syntax-error/TestRunner.cfc b/tests/example-syntax-error/TestRunner.cfc deleted file mode 100644 index c870f90..0000000 --- a/tests/example-syntax-error/TestRunner.cfc +++ /dev/null @@ -1,103 +0,0 @@ -/** -* I am a CommandBox task runner which you can use to test your implementation of this exercise against the -* provided test suite. To use me, open the CommandBox CLI and run this: -* -* CommandBox> task run TestRunner -* -* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: -* -* CommandBox> task run TestRunner --watcher -* -*/ -component { - - /** - * @solution Runs the tests against the solution - * @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop - */ - function run( boolean solution=false, boolean watcher=false ) { - - ensureTestBox(); - - if( watcher ) { - - // Tabula rasa - command( 'cls' ).run(); - - // Start watcher - watch() - .paths( '*.cfc' ) - .inDirectory( getCWD() ) - .withDelay( 500 ) - .onChange( function() { - - // Clear the screen - command( 'cls' ) - .run(); - - // This is neccessary so changes to tests get picked up right away. - pagePoolClear(); - - runTests( solution ); - - } ) - .start(); - - } else { - runTests( solution ); - } - - } - - /** - * Make sure the TestBox framework is installed - */ - private function ensureTestBox() { - var excerciseRoot = getCWD(); - var testBoxRoot = excerciseRoot & '/testbox'; - - if( !directoryExists( testBoxRoot ) ) { - - print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); - command( 'install' ) - .inWorkingDirectory( excerciseRoot ) - .run(); - } - - // Bootstrap TestBox framework - filesystemUtil.createMapping( '/testbox', testBoxRoot ); - } - - /** - * Invoke TestBox to run the test suite - */ - private function runTests( boolean solution=false ) { - - // Create TestBox and run the tests - testData = new testbox.system.TestBox() - .runRaw( directory = { - // Find all CFCs... - mapping = filesystemUtil.makePathRelative( getCWD() ), - // ... in this directory ... - recurse = false, - // ... whose name ends in "test" - filter = function( path ) { - return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); - } - } ) - .getMemento(); - - // Print out the results with ANSI formatting for the CLI - getInstance( 'CLIRenderer@testbox-cli' ) - .render( print, testData, true ); - - print.toConsole(); - - // Set proper exit code - if( testData.totalFail || testData.totalError ) { - setExitCode( 1 ); - } - } - -} - diff --git a/tests/example-syntax-error/box.json b/tests/example-syntax-error/box.json deleted file mode 100644 index 4e5af44..0000000 --- a/tests/example-syntax-error/box.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies":{ - "testbox":"^2.5.0+107" - }, - "installPaths":{ - "testbox":"testbox" - } -} \ No newline at end of file diff --git a/tests/example-syntax-error/expected_results.json b/tests/example-syntax-error/expected_results.json deleted file mode 100644 index 3b950e6..0000000 --- a/tests/example-syntax-error/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "- opt.test-runner.tests.example-syntax-error.LeapTest\n[Passed: 0] [Failed: 0] [Errors: 7] [Skipped: 0] [Suites/Specs: 0/0]\n\nGLOBAL BUNDLE EXCEPTION\n-> template:Missing [;] or [line feed] after expression:\n-> at /solution/Leap.cfc:1 \r\r\n\n1: componentTTT@@ clazzzz\n\n-> at /solution/LeapTest.cfc:4 \r\r\n-> at /solution/testbox/system/runners/BDDRunner.cfc:58 \r\r\n-> at /solution/testbox/system/TestBox.cfc:461 \r\r\n-> at /solution/testbox/system/TestBox.cfc:243 \r\r\n---------------------------------------------------------------------------------\n\n╔═════════════════════════════════════════════════════════════════════╗\n║ Passed ║ Failed ║ Errored ║ Skipped ║ Bundles ║ Suites ║ Specs ║\n╠═════════════════════════════════════════════════════════════════════╣\n║ 0 ║ 0 ║ 7 ║ 0 ║ 1 ║ 0 ║ 0 ║\n╚═════════════════════════════════════════════════════════════════════╝\n\nTestBox \tv2.8.0+191\nCFML Engine\t\n\nLabels \t\t---\n√ Passed - Skipped !! Exception/Error X Failure\n\n\n\n\u001b[38;5;15m\u001b[48;5;9mERROR (6.0.0+00787)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mTask returned failing exit code (1)\u001b[0m\n\n\u001b[38;5;9m\u001b[1mFailing Task: /solution/TestRunner.cfc run\u001b[0m" -} diff --git a/tests/example-syntax-error/index.cfm b/tests/example-syntax-error/index.cfm deleted file mode 100644 index 1e35079..0000000 --- a/tests/example-syntax-error/index.cfm +++ /dev/null @@ -1,37 +0,0 @@ - - - - - // get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" - // And turn it into compnent path relative to the web root - url.bundles = directoryList( - path=expandPath( '/' ), - filter='*Test.cfc' ) - .map( function( path ) { - return path - .replaceNoCase( expandPath( '/' ), '' ) - .left( -4 ) - } ) - .toList(); - - - - - - - - Oops, you don't have TestBox installed yet! Please run box install from the root of your excercise folder and refresh this page. - diff --git a/tests/fail-if-all-tests-fail/FailIfAllTestsFail.cfc b/tests/fail-if-all-tests-fail/FailIfAllTestsFail.cfc new file mode 100644 index 0000000..5aff2dc --- /dev/null +++ b/tests/fail-if-all-tests-fail/FailIfAllTestsFail.cfc @@ -0,0 +1,12 @@ +component { + + function leapYear( year ) { + if ( year % 400 == 0 ) { + return false; + } else if ( year % 4 == 0 && year % 100 != 0 ) { + return false; + } + return true; + } + +} diff --git a/tests/example-all-fail/LeapTest.cfc b/tests/fail-if-all-tests-fail/FailIfAllTestsFailTest.cfc similarity index 50% rename from tests/example-all-fail/LeapTest.cfc rename to tests/fail-if-all-tests-fail/FailIfAllTestsFailTest.cfc index 891e204..2872621 100644 --- a/tests/example-all-fail/LeapTest.cfc +++ b/tests/fail-if-all-tests-fail/FailIfAllTestsFailTest.cfc @@ -1,23 +1,23 @@ component extends="testbox.system.BaseSpec" { function beforeAll(){ - SUT = createObject( 'Leap' ); + SUT = createObject( 'FailIfAllTestsFail' ); } function run(){ - - describe( "My Leap class", function(){ - it( 'year not divisible by 4: common year', function(){ + describe( 'FailIfAllTestsFail', function(){ + + it( 'this should fail', function(){ expect( SUT.leapYear( year='2015' ) ).toBeFalse(); }); - it( 'year divisible by 4, not divisible by 100: leap year', function(){ + it( 'this should also fail', function(){ expect( SUT.leapYear( year='1996' ) ).toBeTrue(); }); }); - + } - -} \ No newline at end of file + +} diff --git a/tests/fail-if-all-tests-fail/expected_results.json b/tests/fail-if-all-tests-fail/expected_results.json new file mode 100644 index 0000000..46df584 --- /dev/null +++ b/tests/fail-if-all-tests-fail/expected_results.json @@ -0,0 +1,18 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "expect( SUT.leapYear( year='2015' ) ).toBeFalse();", + "message": "Expected [true] to be false", + "name": "this should fail", + "status": "fail" + }, + { + "test_code": "expect( SUT.leapYear( year='1996' ) ).toBeTrue();", + "message": "Expected [false] to be true", + "name": "this should also fail", + "status": "fail" + } + ], + "status": "fail" +} diff --git a/tests/fail-if-only-test-fails/FailIfOnlyTestFails.cfc b/tests/fail-if-only-test-fails/FailIfOnlyTestFails.cfc new file mode 100644 index 0000000..9049056 --- /dev/null +++ b/tests/fail-if-only-test-fails/FailIfOnlyTestFails.cfc @@ -0,0 +1,10 @@ +component { + + /** + * @returns A string greeting the world + */ + function hello() { + return 'Goodbye, Mars!'; + } + +} diff --git a/tests/fail-if-only-test-fails/FailIfOnlyTestFailsTest.cfc b/tests/fail-if-only-test-fails/FailIfOnlyTestFailsTest.cfc new file mode 100644 index 0000000..bf3c67c --- /dev/null +++ b/tests/fail-if-only-test-fails/FailIfOnlyTestFailsTest.cfc @@ -0,0 +1,19 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'FailIfOnlyTestFails' ); + } + + function run(){ + + describe( 'FailIfOnlyTestFails', function(){ + + it( 'This should fail', function(){ + expect( SUT.hello() ).toBe( 'Hello, World!' ); + }); + + }); + + } + +} diff --git a/tests/fail-if-only-test-fails/expected_results.json b/tests/fail-if-only-test-fails/expected_results.json new file mode 100644 index 0000000..1385339 --- /dev/null +++ b/tests/fail-if-only-test-fails/expected_results.json @@ -0,0 +1,12 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "expect( SUT.hello() ).toBe( 'Hello, World!' );", + "message": "Expected [Hello, World!] but received [Goodbye, Mars!]", + "name": "This should fail", + "status": "fail" + } + ], + "status": "fail" +} diff --git a/tests/fail-if-some-tests-fail/FailIfSomeTestsFail.cfc b/tests/fail-if-some-tests-fail/FailIfSomeTestsFail.cfc new file mode 100644 index 0000000..7630009 --- /dev/null +++ b/tests/fail-if-some-tests-fail/FailIfSomeTestsFail.cfc @@ -0,0 +1,7 @@ +component { + + function returnsTrue() { + return true; + } + +} diff --git a/tests/fail-if-some-tests-fail/FailIfSomeTestsFailTest.cfc b/tests/fail-if-some-tests-fail/FailIfSomeTestsFailTest.cfc new file mode 100644 index 0000000..997ce5d --- /dev/null +++ b/tests/fail-if-some-tests-fail/FailIfSomeTestsFailTest.cfc @@ -0,0 +1,23 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'FailIfSomeTestsFail' ); + } + + function run(){ + + describe( 'FailIfSomeTestsFail', function(){ + + it( 'this should pass', function(){ + expect( SUT.returnsTrue() ).toBeTrue(); + }); + + it( 'this should fail', function(){ + expect( SUT.returnsTrue() ).toBeFalse(); + }); + + }); + + } + +} diff --git a/tests/fail-if-some-tests-fail/expected_results.json b/tests/fail-if-some-tests-fail/expected_results.json new file mode 100644 index 0000000..f74778b --- /dev/null +++ b/tests/fail-if-some-tests-fail/expected_results.json @@ -0,0 +1,17 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "expect( SUT.returnsTrue() ).toBeTrue();", + "name": "this should pass", + "status": "pass" + }, + { + "test_code": "expect( SUT.returnsTrue() ).toBeFalse();", + "message": "Expected [true] to be false", + "name": "this should fail", + "status": "fail" + } + ], + "status": "fail" +} diff --git a/tests/misc-longer-test-code/MiscLongerTestCode.cfc b/tests/misc-longer-test-code/MiscLongerTestCode.cfc new file mode 100644 index 0000000..e9236ba --- /dev/null +++ b/tests/misc-longer-test-code/MiscLongerTestCode.cfc @@ -0,0 +1,18 @@ +component { + + MiscLongerTestCode function init () { + variables.data = []; + return this; + } + + numeric function read() { + var value = variables.data[ 1 ]; + variables.data.deleteAt( 1 ); + return value; + } + + void function write( required numeric value ) { + variables.data.append( arguments.value ); + } + +} diff --git a/tests/misc-longer-test-code/MiscLongerTestCodeTest.cfc b/tests/misc-longer-test-code/MiscLongerTestCodeTest.cfc new file mode 100644 index 0000000..6e04f84 --- /dev/null +++ b/tests/misc-longer-test-code/MiscLongerTestCodeTest.cfc @@ -0,0 +1,25 @@ +component extends="testbox.system.BaseSpec" { + + function run(){ + + describe( 'MiscLongerTestCode', function(){ + + it( 'reports multiline test code', function(){ + SUT = new MiscLongerTestCode(); + SUT.write( 1 ); + expect( SUT.read() ).toBe( 1 ); + }); + + it( 'reports multiple expects', function(){ + SUT = new MiscLongerTestCode(); + SUT.write( 1 ); + SUT.write( 2 ); + expect( SUT.read() ).toBe( 1 ); + expect( SUT.read() ).toBe( 2 ); + }); + + }); + + } + +} diff --git a/tests/misc-longer-test-code/expected_results.json b/tests/misc-longer-test-code/expected_results.json new file mode 100644 index 0000000..be91210 --- /dev/null +++ b/tests/misc-longer-test-code/expected_results.json @@ -0,0 +1,16 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "SUT = new MiscLongerTestCode();\n\t\t\t\tSUT.write( 1 );\n\t\t\t\texpect( SUT.read() ).toBe( 1 );", + "name": "reports multiline test code", + "status": "pass" + }, + { + "test_code": "SUT = new MiscLongerTestCode();\n\t\t\t\tSUT.write( 1 );\n\t\t\t\tSUT.write( 2 );\n\t\t\t\texpect( SUT.read() ).toBe( 1 );\n\t\t\t\texpect( SUT.read() ).toBe( 2 );", + "name": "reports multiple expects", + "status": "pass" + } + ], + "status": "pass" +} diff --git a/tests/example-success/Leap.cfc b/tests/pass-if-all-tests-pass/PassIfAllTestsPass.cfc similarity index 82% rename from tests/example-success/Leap.cfc rename to tests/pass-if-all-tests-pass/PassIfAllTestsPass.cfc index 3ce2ed2..f591ba5 100644 --- a/tests/example-success/Leap.cfc +++ b/tests/pass-if-all-tests-pass/PassIfAllTestsPass.cfc @@ -1,6 +1,3 @@ -/** -* Here is an example solution for the Leap exercise -*/ component { /** @@ -16,4 +13,5 @@ component { } return false; } -} \ No newline at end of file + +} diff --git a/tests/pass-if-all-tests-pass/PassIfAllTestsPassTest.cfc b/tests/pass-if-all-tests-pass/PassIfAllTestsPassTest.cfc new file mode 100644 index 0000000..5ae6114 --- /dev/null +++ b/tests/pass-if-all-tests-pass/PassIfAllTestsPassTest.cfc @@ -0,0 +1,23 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'PassIfAllTestsPass' ); + } + + function run(){ + + describe( 'PassIfAllTestsPass', function(){ + + it( 'this should pass', function(){ + expect( SUT.leapYear( year='2015' ) ).toBeFalse(); + }); + + it( 'this should also pass', function(){ + expect( SUT.leapYear( year='1996' ) ).toBeTrue(); + }); + + }); + + } + +} diff --git a/tests/pass-if-all-tests-pass/expected_results.json b/tests/pass-if-all-tests-pass/expected_results.json new file mode 100644 index 0000000..b21a47a --- /dev/null +++ b/tests/pass-if-all-tests-pass/expected_results.json @@ -0,0 +1,16 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "expect( SUT.leapYear( year='2015' ) ).toBeFalse();", + "name": "this should pass", + "status": "pass" + }, + { + "test_code": "expect( SUT.leapYear( year='1996' ) ).toBeTrue();", + "name": "this should also pass", + "status": "pass" + } + ], + "status": "pass" +} diff --git a/tests/pass-if-only-test-passes/PassIfOnlyTestPasses.cfc b/tests/pass-if-only-test-passes/PassIfOnlyTestPasses.cfc new file mode 100644 index 0000000..5003cea --- /dev/null +++ b/tests/pass-if-only-test-passes/PassIfOnlyTestPasses.cfc @@ -0,0 +1,10 @@ +component { + + /** + * @returns A string greeting the world + */ + function hello() { + return 'Hello, World!'; + } + +} diff --git a/tests/pass-if-only-test-passes/PassIfOnlyTestPassesTest.cfc b/tests/pass-if-only-test-passes/PassIfOnlyTestPassesTest.cfc new file mode 100644 index 0000000..5c47001 --- /dev/null +++ b/tests/pass-if-only-test-passes/PassIfOnlyTestPassesTest.cfc @@ -0,0 +1,19 @@ +component extends="testbox.system.BaseSpec" { + + function beforeAll(){ + SUT = createObject( 'PassIfOnlyTestPasses' ); + } + + function run(){ + + describe( 'PassIfOnlyTestPasses', function(){ + + it( 'This should pass', function(){ + expect( SUT.hello() ).toBe( 'Hello, World!' ); + }); + + }); + + } + +} diff --git a/tests/pass-if-only-test-passes/expected_results.json b/tests/pass-if-only-test-passes/expected_results.json new file mode 100644 index 0000000..6dd5b1a --- /dev/null +++ b/tests/pass-if-only-test-passes/expected_results.json @@ -0,0 +1,11 @@ +{ + "version": 2, + "tests": [ + { + "test_code": "expect( SUT.hello() ).toBe( 'Hello, World!' );", + "name": "This should pass", + "status": "pass" + } + ], + "status": "pass" +}