Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add betterC support - fixes #1636 #2581

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}