diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6490ae..4c3583f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ FRONTEND: 2.093.0 run: | dub build --compiler=${{ env.DC }} - dub run --compiler=${{ env.DC }} --single test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d + dub run --compiler=${{ env.DC }} --single test/issue2051_running_unittests_from_dub_single_file_packages_fails.d ./scripts/ci/travis.sh - name: '[Windows] Test' @@ -74,4 +74,4 @@ run: | dub build --compiler=${{ env.DC }} dub test --compiler=${{ env.DC }} - dub run --compiler=${{ env.DC }} --single test\issue_2051_running_unittests_from_dub_single_file_packages_fails.d + dub run --compiler=${{ env.DC }} --single test\issue2051_running_unittests_from_dub_single_file_packages_fails.d diff --git a/test/issue2051_running_unittests_from_dub_single_file_packages_fails.d b/test/issue2051_running_unittests_from_dub_single_file_packages_fails.d new file mode 100644 index 0000000..2327db3 --- /dev/null +++ b/test/issue2051_running_unittests_from_dub_single_file_packages_fails.d @@ -0,0 +1,99 @@ +/+ dub.sdl: + name "issue2051_running_unittests_from_dub_single_file_packages_fails" + +/ + +import std.algorithm : any; +import std.conv : text; +import std.file : tempDir; +import std.stdio : File, writeln; +import std.string : lineSplitter; +import std.path : buildPath; +import std.process : environment, executeShell; + +auto executeCommand(string command) +{ + import std.exception : enforce; + + auto dub = executeShell(command); + writeln("--- dub output:"); + foreach(line; dub.output.lineSplitter) + writeln("\t", line); + writeln("--- end of dub output"); + + return dub.status; +} + +int main() +{ + auto dub = environment.get("DUB"); + if (!dub.length) + dub = buildPath(".", "bin", "dub"); + + string filename; + // check if the single file package with dependency compiles and runs + { + filename = tempDir.buildPath("issue2051_success.d"); + auto f = File(filename, "w"); + f.write( +`#!/usr/bin/env dub +/+ dub.sdl: + name "issue2051" + dependency "taggedalgebraic" version="~>0.11.0" ++/ + +version(unittest) {} +else void main() +{ +} + +unittest +{ + import taggedalgebraic; + + static union Base { + int i; + string str; + } + + auto dummy = TaggedAlgebraic!Base(1721); + assert(dummy == 1721); +} +` ); + } + + const rc1 = text(dub, " test --single ", filename).executeCommand; + if (rc1) + writeln("\nError. Unittests failed."); + else + writeln("\nOk. Unittest passed."); + + // Check if dub `test` command runs unittests for single file package + { + filename = tempDir.buildPath("issue2051_fail.d"); + auto f = File(filename, "w"); + f.write( +`#!/usr/bin/env dub +/+ dub.sdl: + name "issue2051" ++/ + +version(unittest) {} +else void main() +{ +} + +unittest +{ + assert(0); +} +` ); + } + + const rc2 = text(dub, " test --single ", filename).executeCommand; + if (rc2) + writeln("\nOk. Unittests failed."); + else + writeln("\nError. Unittest passed."); + + return rc1 | !rc2; +} \ No newline at end of file diff --git a/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d b/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d deleted file mode 100644 index 3769892..0000000 --- a/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d +++ /dev/null @@ -1,99 +0,0 @@ -/+ dub.sdl: - name "issue_2051_running_unittests_from_dub_single_file_packages_fails" - +/ - -import std.algorithm : any; -import std.conv : text; -import std.file : tempDir; -import std.stdio : File, writeln; -import std.string : lineSplitter; -import std.path : buildPath; -import std.process : environment, executeShell; - -auto executeCommand(string command) -{ - import std.exception : enforce; - - auto dub = executeShell(command); - writeln("--- dub output:"); - foreach(line; dub.output.lineSplitter) - writeln("\t", line); - writeln("--- end of dub output"); - - return dub.status; -} - -int main() -{ - auto dub = environment.get("DUB"); - if (!dub.length) - dub = buildPath(".", "bin", "dub"); - - string filename; - // check if the single file package with dependency compiles and runs - { - filename = tempDir.buildPath("issue2051_success.d"); - auto f = File(filename, "w"); - f.write( -`#!/usr/bin/env dub -/+ dub.sdl: - name "issue2051" - dependency "taggedalgebraic" version="~>0.11.0" -+/ - -version(unittest) {} -else void main() -{ -} - -unittest -{ - import taggedalgebraic; - - static union Base { - int i; - string str; - } - - auto dummy = TaggedAlgebraic!Base(1721); - assert(dummy == 1721); -} -` ); - } - - const rc1 = text(dub, " test --single ", filename).executeCommand; - if (rc1) - writeln("\nError. Unittests failed."); - else - writeln("\nOk. Unittest passed."); - - // Check if dub `test` command runs unittests for single file package - { - filename = tempDir.buildPath("issue2051_fail.d"); - auto f = File(filename, "w"); - f.write( -`#!/usr/bin/env dub -/+ dub.sdl: - name "issue2051" -+/ - -version(unittest) {} -else void main() -{ -} - -unittest -{ - assert(0); -} -` ); - } - - const rc2 = text(dub, " test --single ", filename).executeCommand; - if (rc2) - writeln("\nOk. Unittests failed."); - else - writeln("\nError. Unittest passed."); - - return rc1 | !rc2; -} \ No newline at end of file