From e5818ba60c885956771296f4114dfa40395c2f63 Mon Sep 17 00:00:00 2001 From: Etienne Cimon Date: Wed, 8 Feb 2023 13:04:14 -0500 Subject: [PATCH 1/4] Add betterC support - fixes #1636 --- source/dub/project.d | 45 +++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/source/dub/project.d b/source/dub/project.d index dc3a84974..acd5ba1ff 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1916,22 +1916,33 @@ alias allModules = TypeTuple!( /// The default test runner that gets used if none is provided private immutable DefaultTestRunnerCode = q{ -import core.runtime; - -void main() { - version (D_Coverage) { + version(D_BetterC) { + extern(C) int main() { + foreach (module_; allModules) { + foreach (unitTest; __traits(getUnitTests, module_)) { + unitTest(); + } + } + import core.stdc.stdio : puts; + puts("All unit tests have been run successfully."); + return 0; + } } else { - import std.stdio : writeln; - writeln("All unit tests have been run successfully."); - } -} -shared static this() { - version (Have_tested) { - import tested; - import core.runtime; - import std.exception; - Runtime.moduleUnitTester = () => true; - enforce(runUnitTests!allModules(new ConsoleTestResultWriter), "Unit tests failed."); + void main() { + version (D_Coverage) { + } else { + import std.stdio : writeln; + writeln("All unit tests have been run successfully."); + } + } + shared static this() { + version (Have_tested) { + import tested; + import core.runtime; + import std.exception; + Runtime.moduleUnitTester = () => true; + enforce(runUnitTests!allModules(new ConsoleTestResultWriter), "Unit tests failed."); + } + } } -} -}; +}; \ No newline at end of file From bd834ad0cdbd89abebb734670c3ae6b9366c9163 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Thu, 9 Feb 2023 12:14:26 +0100 Subject: [PATCH 2/4] add test case for #1636 --- test/issue1636-betterC-dub-test.sh | 5 +++++ test/issue1636-betterC-dub-test/.gitignore | 4 ++++ test/issue1636-betterC-dub-test/.min_frontend | 1 + test/issue1636-betterC-dub-test/dub.json | 4 ++++ test/issue1636-betterC-dub-test/source/lib.d | 14 ++++++++++++++ 5 files changed, 28 insertions(+) create mode 100755 test/issue1636-betterC-dub-test.sh create mode 100644 test/issue1636-betterC-dub-test/.gitignore create mode 100644 test/issue1636-betterC-dub-test/.min_frontend create mode 100644 test/issue1636-betterC-dub-test/dub.json create mode 100644 test/issue1636-betterC-dub-test/source/lib.d diff --git a/test/issue1636-betterC-dub-test.sh b/test/issue1636-betterC-dub-test.sh new file mode 100755 index 000000000..0b1f737f0 --- /dev/null +++ b/test/issue1636-betterC-dub-test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd ${CURR_DIR}/issue1636-betterC-dub-test + +${DUB} test | grep -c "TEST_WAS_RUN" > /dev/null \ No newline at end of file diff --git a/test/issue1636-betterC-dub-test/.gitignore b/test/issue1636-betterC-dub-test/.gitignore new file mode 100644 index 000000000..0fd9d379b --- /dev/null +++ b/test/issue1636-betterC-dub-test/.gitignore @@ -0,0 +1,4 @@ +test +*.o +*.exe +.dub \ No newline at end of file diff --git a/test/issue1636-betterC-dub-test/.min_frontend b/test/issue1636-betterC-dub-test/.min_frontend new file mode 100644 index 000000000..67aaf4ad8 --- /dev/null +++ b/test/issue1636-betterC-dub-test/.min_frontend @@ -0,0 +1 @@ +2.078 diff --git a/test/issue1636-betterC-dub-test/dub.json b/test/issue1636-betterC-dub-test/dub.json new file mode 100644 index 000000000..d6e925663 --- /dev/null +++ b/test/issue1636-betterC-dub-test/dub.json @@ -0,0 +1,4 @@ +{ + "name": "test", + "buildOptions": ["betterC"] +} \ No newline at end of file diff --git a/test/issue1636-betterC-dub-test/source/lib.d b/test/issue1636-betterC-dub-test/source/lib.d new file mode 100644 index 000000000..1d2807ed7 --- /dev/null +++ b/test/issue1636-betterC-dub-test/source/lib.d @@ -0,0 +1,14 @@ +import core.stdc.stdio : printf; + +version(D_BetterC) {} else static assert(false); + +int foo() +{ + return 2; +} + +unittest +{ + assert(foo == 2); + printf("TEST_WAS_RUN\n"); +} From c6b29272cebf8c609a795f09df51ea70da785802 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Thu, 9 Feb 2023 12:17:34 +0100 Subject: [PATCH 3/4] add EOF EOLs --- source/dub/project.d | 2 +- test/issue1636-betterC-dub-test.sh | 2 +- test/issue1636-betterC-dub-test/.gitignore | 2 +- test/issue1636-betterC-dub-test/dub.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/dub/project.d b/source/dub/project.d index acd5ba1ff..d6bde0145 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1945,4 +1945,4 @@ private immutable DefaultTestRunnerCode = q{ } } } -}; \ No newline at end of file +}; diff --git a/test/issue1636-betterC-dub-test.sh b/test/issue1636-betterC-dub-test.sh index 0b1f737f0..f2062c628 100755 --- a/test/issue1636-betterC-dub-test.sh +++ b/test/issue1636-betterC-dub-test.sh @@ -2,4 +2,4 @@ cd ${CURR_DIR}/issue1636-betterC-dub-test -${DUB} test | grep -c "TEST_WAS_RUN" > /dev/null \ No newline at end of file +${DUB} test | grep -c "TEST_WAS_RUN" > /dev/null diff --git a/test/issue1636-betterC-dub-test/.gitignore b/test/issue1636-betterC-dub-test/.gitignore index 0fd9d379b..53b683b0a 100644 --- a/test/issue1636-betterC-dub-test/.gitignore +++ b/test/issue1636-betterC-dub-test/.gitignore @@ -1,4 +1,4 @@ test *.o *.exe -.dub \ No newline at end of file +.dub diff --git a/test/issue1636-betterC-dub-test/dub.json b/test/issue1636-betterC-dub-test/dub.json index d6e925663..afb1093ea 100644 --- a/test/issue1636-betterC-dub-test/dub.json +++ b/test/issue1636-betterC-dub-test/dub.json @@ -1,4 +1,4 @@ { "name": "test", "buildOptions": ["betterC"] -} \ No newline at end of file +} From a7f31f43fd052be387b7b587451a6eb54118534b Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Thu, 9 Feb 2023 12:23:53 +0100 Subject: [PATCH 4/4] .no_run on betterC dub test --- test/issue1636-betterC-dub-test/.no_run | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/issue1636-betterC-dub-test/.no_run diff --git a/test/issue1636-betterC-dub-test/.no_run b/test/issue1636-betterC-dub-test/.no_run new file mode 100644 index 000000000..e69de29bb