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/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 f51b5d5..2183e91 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) {