Skip to content

Commit

Permalink
Add betterC support - fixes #1636 (#2581)
Browse files Browse the repository at this point in the history
Co-authored-by: Etienne Cimon <etcimon@gmail.com>
Co-authored-by: WebFreak001 <gh@webfreak.org>
  • Loading branch information
3 people authored Feb 9, 2023
1 parent 5f756ca commit 89f9b8e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
43 changes: 27 additions & 16 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
}
};
5 changes: 5 additions & 0 deletions test/issue1636-betterC-dub-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd ${CURR_DIR}/issue1636-betterC-dub-test

${DUB} test | grep -c "TEST_WAS_RUN" > /dev/null
4 changes: 4 additions & 0 deletions test/issue1636-betterC-dub-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test
*.o
*.exe
.dub
1 change: 1 addition & 0 deletions test/issue1636-betterC-dub-test/.min_frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.078
Empty file.
4 changes: 4 additions & 0 deletions test/issue1636-betterC-dub-test/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test",
"buildOptions": ["betterC"]
}
14 changes: 14 additions & 0 deletions test/issue1636-betterC-dub-test/source/lib.d
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit 89f9b8e

Please sign in to comment.