Skip to content

Commit d6bcccd

Browse files
authored
Merge pull request #109 from vushu/opend/added_test_runner
Added test_runner to opend for selective testing
2 parents 44d6a9f + 9e7742f commit d6bcccd

File tree

2 files changed

+493
-0
lines changed

2 files changed

+493
-0
lines changed

opend/opend.d

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import std.process;
22
import std.file;
3+
import test_runner;
34

45
// **********************FIXME: when we call spawnProcess it doesn't print an error (though it does return a code) when the process segfaults.
56

@@ -135,9 +136,96 @@ struct Commands {
135136

136137
/// Builds the code and runs its unittests
137138
int test(string[] args) {
139+
// Check if user wants advanced test runner features
140+
if(args.length > 0) {
141+
switch(args[0]) {
142+
case "list":
143+
return testList(args[1..$]);
144+
case "filter":
145+
return testFilter(args[1..$]);
146+
case "run":
147+
return testRun(args[1..$]);
148+
case "--help", "-h":
149+
// Delegate to test runner's help system to avoid duplication
150+
auto buildArgs = ["-g", "-unittest", "-checkaction=context", "test_runner.d"];
151+
auto oe = getOutputExecutable(buildArgs);
152+
153+
if(auto err = build(oe.buildArgs))
154+
return err;
155+
156+
return spawnProcess([oe.exe, "help"], [
157+
"LD_LIBRARY_PATH": getRuntimeLibPath()
158+
]).wait.checkForCrash("test runner");
159+
case "help":
160+
// Also handle "opend test help"
161+
goto case "--help";
162+
default:
163+
// Fall through to normal test execution
164+
break;
165+
}
166+
}
167+
168+
// Original test behavior - run all tests
138169
return run(["-g", "-unittest", "-main", "-checkaction=context"] ~ args);
139170
}
140171

172+
private int testList(string[] args) {
173+
// Build executable with test runner embedded (no -main since test_runner.d has its own)
174+
auto buildArgs = ["-g", "-unittest", "-checkaction=context",
175+
"test_runner.d"] ~ args;
176+
auto oe = getOutputExecutable(buildArgs);
177+
178+
if(auto err = build(oe.buildArgs))
179+
return err;
180+
181+
return spawnProcess([oe.exe, "list"] ~ oe.args, [
182+
"LD_LIBRARY_PATH": getRuntimeLibPath()
183+
]).wait.checkForCrash("test runner");
184+
}
185+
186+
private int testFilter(string[] args) {
187+
if(args.length == 0) {
188+
import std.stdio;
189+
stderr.writeln("Error: Please specify a filter pattern.");
190+
stderr.writeln("Usage: opend test filter <pattern>");
191+
stderr.writeln("Example: opend test filter \"Math*\"");
192+
return 1;
193+
}
194+
195+
// Build executable with test runner embedded (no -main since test_runner.d has its own)
196+
auto buildArgs = ["-g", "-unittest", "-checkaction=context",
197+
"test_runner.d"] ~ args[1..$];
198+
auto oe = getOutputExecutable(buildArgs);
199+
200+
if(auto err = build(oe.buildArgs))
201+
return err;
202+
203+
return spawnProcess([oe.exe, "filter", args[0]] ~ oe.args, [
204+
"LD_LIBRARY_PATH": getRuntimeLibPath()
205+
]).wait.checkForCrash("test runner");
206+
}
207+
208+
private int testRun(string[] args) {
209+
if(args.length == 0) {
210+
import std.stdio;
211+
stderr.writeln("Error: Please specify a test name.");
212+
stderr.writeln("Usage: opend test run <test_name>");
213+
return 1;
214+
}
215+
216+
// Build executable with test runner embedded (no -main since test_runner.d has its own)
217+
auto buildArgs = ["-g", "-unittest", "-checkaction=context",
218+
"test_runner.d"] ~ args[1..$];
219+
auto oe = getOutputExecutable(buildArgs);
220+
221+
if(auto err = build(oe.buildArgs))
222+
return err;
223+
224+
return spawnProcess([oe.exe, "run", args[0]] ~ oe.args, [
225+
"LD_LIBRARY_PATH": getRuntimeLibPath()
226+
]).wait.checkForCrash("test runner");
227+
}
228+
141229
/// Builds the code and runs unittests but only for files explicitly listed, not auto-imported files
142230
int testOnly(string[] args) {
143231
return run(["-g", "-unittest=explicit", "-main", "-checkaction=context"] ~ args);

0 commit comments

Comments
 (0)