|
1 | 1 | import std.process; |
2 | 2 | import std.file; |
| 3 | +import test_runner; |
3 | 4 |
|
4 | 5 | // **********************FIXME: when we call spawnProcess it doesn't print an error (though it does return a code) when the process segfaults. |
5 | 6 |
|
@@ -135,9 +136,96 @@ struct Commands { |
135 | 136 |
|
136 | 137 | /// Builds the code and runs its unittests |
137 | 138 | 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 |
138 | 169 | return run(["-g", "-unittest", "-main", "-checkaction=context"] ~ args); |
139 | 170 | } |
140 | 171 |
|
| 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 | + |
141 | 229 | /// Builds the code and runs unittests but only for files explicitly listed, not auto-imported files |
142 | 230 | int testOnly(string[] args) { |
143 | 231 | return run(["-g", "-unittest=explicit", "-main", "-checkaction=context"] ~ args); |
|
0 commit comments