diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e66a488..24d2b1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,9 +69,13 @@ - name: '[Windows] Test' if: runner.os == 'Windows' + env: + DUB: ${{ github.workspace }}\bin\dub.exe # Only run `dub test` to run unittests so far, # the test-suite needs to be overhauled to support Windows run: | dub build --compiler=${{ env.DC }} dub test --compiler=${{ env.DC }} dub run --compiler=${{ env.DC }} --single test\issue2051_running_unittests_from_dub_single_file_packages_fails.d + cd test + dub --single run-unittest.d diff --git a/.gitignore b/.gitignore index 06b77b4..e0ee768 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,8 @@ /test/*/*test-application /test/*/exec-simple /test/issue1474/ext/fortytwo.d +*.exe +*.log # Ignore coverage files cov/ diff --git a/test/.gitignore b/test/.gitignore index 6b02e75..7170394 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -18,3 +18,4 @@ /test_registry /issue_2051_running_unittests_from_dub_single_file_packages_fails +/run-unittest diff --git a/test/0-init-fail-json.script.d b/test/0-init-fail-json.script.d new file mode 100644 index 0000000..d629385 --- /dev/null +++ b/test/0-init-fail-json.script.d @@ -0,0 +1,36 @@ +/+ dub.sdl: + name "0-init-fail-json" + dependency "common" path="./common" + +/ + +module _0_init_fail_json; + +import std.file : exists, remove; +import std.path : buildPath; +import std.process : environment, spawnProcess, wait; + +import common; + +int main() +{ + enum packname = "0-init-fail-pack"; + enum deps = "logger PACKAGE_DONT_EXIST"; // would be very unlucky if it does exist... + + auto dub = environment.get("DUB"); + if (!dub.length) + die(`Environment variable "DUB" must be defined to run the tests.`); + + //** if $$DUB init -n $packname $deps -f json 2>/dev/null; then + if (!spawnProcess([dub, "init", "-n", packname, deps, "-f", "json"]).wait) + die("Init with unknown non-existing dependency expected to fail"); + + //** if [ -e $packname/dub.json ]; then # package is there, it should have failed + const filepath = buildPath(packname, "dub.json"); + if (filepath.exists) + { + remove(packname); + die(filepath ~ " was not created"); + } + + return 0; +} diff --git a/test/0-init-fail-json.sh b/test/0-init-fail-json.sh deleted file mode 100755 index 069014e..0000000 --- a/test/0-init-fail-json.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -. $(dirname "${BASH_SOURCE[0]}")/common.sh -packname="0-init-fail-pack" -deps="logger PACKAGE_DONT_EXIST" # would be very unlucky if it does exist... - -if $$DUB init -n $packname $deps -f json 2>/dev/null; then - die $LINENO 'Init with unknown non-existing dependency expected to fail' -fi - - -function cleanup { - rm -rf $packname -} - -if [ -e $packname/dub.json ]; then # package is there, it should have failed - cleanup - die $LINENO "$packname/dub.json was not created" -fi diff --git a/test/common/.no_build b/test/common/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/common/.no_build diff --git a/test/common/.no_run b/test/common/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/common/.no_run diff --git a/test/common/.no_test b/test/common/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/common/.no_test diff --git a/test/common/dub.sdl b/test/common/dub.sdl new file mode 100644 index 0000000..07cd175 --- /dev/null +++ b/test/common/dub.sdl @@ -0,0 +1,6 @@ +name "common" +description "Utility package for test suite" +authors "drug007" +copyright "The D language Foundation" +license "BSL-1.0" +targetType "sourceLibrary" diff --git a/test/common/source/common.d b/test/common/source/common.d new file mode 100644 index 0000000..796a059 --- /dev/null +++ b/test/common/source/common.d @@ -0,0 +1,40 @@ +module common; + +import std.conv : text; +import std.stdio : File, stdout, stderr; + +/// Name of the log file +enum logFile = "test.log"; + +/// has true if some test fails +bool any_errors = false; + +/// prints (non error) message to standard output and log file +void log(Args...)(Args args) + if (Args.length) +{ + const str = text("[INFO] ", args); + version(Windows) stdout.writeln(str); + else stdout.writeln("\033[0;33m", str, "\033[0m"); + stdout.flush; + File(logFile, "a").writeln(str); +} + +/// prints error message to standard error stream and log file +/// and set any_errors var to true value to indicate that some +/// test fails +void logError(Args...)(Args args) +{ + const str = text("[ERROR] ", args); + version(Windows) stderr.writeln(str); + else stderr.writeln("\033[0;31m", str, "\033[0m"); + stderr.flush; + File(logFile, "a").writeln(str); + any_errors = true; +} + +void die(Args...)(Args args) +{ + stderr.writeln(args); + throw new Exception("Test failed"); +} diff --git a/test/run-unittest.d b/test/run-unittest.d index 5575743..e2b2e26 100644 --- a/test/run-unittest.d +++ b/test/run-unittest.d @@ -2,44 +2,11 @@ /+dub.sdl: name: run_unittest targetName: run-unittest + dependency "common" path="./common" +/ module run_unittest; -/// Name of the log file -enum logFile = "test.log"; - -/// has true if some test fails -bool any_errors = false; - -/// prints (non error) message to standard output and log file -void log(Args...)(Args args) - if (Args.length) -{ - import std.conv : text; - import std.stdio : File, stdout; - - const str = text("[INFO] ", args); - version(Windows) stdout.writeln(str); - else stdout.writeln("\033[0;33m", str, "\033[0m"); - stdout.flush; - File(logFile, "a").writeln(str); -} - -/// prints error message to standard error stream and log file -/// and set any_errors var to true value to indicate that some -/// test fails -void logError(Args...)(Args args) -{ - import std.conv : text; - import std.stdio : File, stderr; - - const str = text("[ERROR] ", args); - version(Windows) stderr.writeln(str); - else stderr.writeln("\033[0;31m", str, "\033[0m"); - stderr.flush; - File(logFile, "a").writeln(str); - any_errors = true; -} +import common; int main(string[] args) { @@ -54,7 +21,6 @@ //** die $LINENO 'Variable $DUB must be defined to run the tests.' //** fi auto dub = environment.get("DUB", ""); - writeln("DUB: ", dub); if (dub == "") { logError(`Environment variable "DUB" must be defined to run the tests.`); @@ -81,13 +47,13 @@ //** CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) //** FRONTEND="${FRONTEND:-}" const dc_bin = baseName(dc); - const curr_dir = args[0].absolutePath.dirName.buildNormalizedPath; + const curr_dir = __FILE_FULL_PATH__.dirName(); const frontend = environment.get("FRONTEND", ""); //** if [ "$#" -gt 0 ]; then FILTER=$1; else FILTER=".*"; fi auto filter = (args.length > 1) ? args[1] : "*"; - version(linux) + version (Posix) { //** for script in $(ls $CURR_DIR/*.sh); do //** if [[ ! "$script" =~ $FILTER ]]; then continue; fi @@ -107,5 +73,16 @@ } } + foreach (DirEntry script; dirEntries(curr_dir, (args.length > 1) ? args[1] : "*.script.d", SpanMode.shallow)) + { + const min_frontend = script.name ~ ".min_frontend"; + if (frontend.length && exists(min_frontend) && frontend < min_frontend.readText) continue; + log("Running " ~ script ~ "..."); + if (spawnProcess([dub, script.name], ["DUB":dub, "DC":dc, "CURR_DIR":curr_dir]).wait) + logError("Script failure."); + else + log(script.name, " status: Ok"); + } + return any_errors; }