| 1 |
module runminitest; |
|---|
| 2 |
|
|---|
| 3 |
import tango.io.FileSystem, |
|---|
| 4 |
tango.io.Stdout, |
|---|
| 5 |
tango.io.vfs.FileFolder; |
|---|
| 6 |
import Path = tango.io.Path; |
|---|
| 7 |
import Util = tango.text.Util; |
|---|
| 8 |
import tango.text.convert.Format; |
|---|
| 9 |
import tango.stdc.stdlib, |
|---|
| 10 |
tango.stdc.stringz; |
|---|
| 11 |
|
|---|
| 12 |
int main(char[][] args) |
|---|
| 13 |
{ |
|---|
| 14 |
enum : int |
|---|
| 15 |
{ |
|---|
| 16 |
COMPILE, |
|---|
| 17 |
NOCOMPILE, |
|---|
| 18 |
RUN, |
|---|
| 19 |
NORUN |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
char[][] compilefailed; |
|---|
| 23 |
char[][] nocompilefailed; |
|---|
| 24 |
char[][] runfailed; |
|---|
| 25 |
char[][] norunfailed; |
|---|
| 26 |
|
|---|
| 27 |
FileSystem.setDirectory("mini"); |
|---|
| 28 |
|
|---|
| 29 |
if (!Path.exists("obj")) |
|---|
| 30 |
Path.createFolder("obj"); |
|---|
| 31 |
|
|---|
| 32 |
foreach(f; Path.children("./obj")) |
|---|
| 33 |
{ |
|---|
| 34 |
Path.remove(f.path ~ f.name); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
static int classify(char[] name) |
|---|
| 38 |
{ |
|---|
| 39 |
char[] tail; |
|---|
| 40 |
char[] desc = Util.head(name, "_", tail); |
|---|
| 41 |
if ("compile" == desc) |
|---|
| 42 |
return COMPILE; |
|---|
| 43 |
else if ("nocompile" == desc) |
|---|
| 44 |
return NOCOMPILE; |
|---|
| 45 |
else if ("run" == desc) |
|---|
| 46 |
return RUN; |
|---|
| 47 |
else if ("norun" == desc) |
|---|
| 48 |
return NORUN; |
|---|
| 49 |
return RUN; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
auto scan = new FileFolder ("."); |
|---|
| 53 |
auto contents = scan.tree.catalog("*.d"); |
|---|
| 54 |
foreach(c; contents) { |
|---|
| 55 |
auto testname = Path.parse(c.name).name; |
|---|
| 56 |
Stdout.formatln("TEST NAME: {}", testname); |
|---|
| 57 |
|
|---|
| 58 |
char[] cmd = Format.convert("ldc {} -quiet -L-s -ofobj/{}", c, testname); |
|---|
| 59 |
foreach(v; args[1..$]) { |
|---|
| 60 |
cmd ~= ' '; |
|---|
| 61 |
cmd ~= v; |
|---|
| 62 |
} |
|---|
| 63 |
int cl = classify(testname); |
|---|
| 64 |
if (cl == COMPILE || cl == NOCOMPILE) |
|---|
| 65 |
cmd ~= " -c"; |
|---|
| 66 |
Stdout(cmd).newline; |
|---|
| 67 |
if (system(toStringz(cmd)) != 0) { |
|---|
| 68 |
if (cl != NOCOMPILE) |
|---|
| 69 |
compilefailed ~= c.toString; |
|---|
| 70 |
} |
|---|
| 71 |
else if (cl == RUN || cl == NORUN) { |
|---|
| 72 |
if (system(toStringz(Path.native("obj/" ~ testname))) != 0) { |
|---|
| 73 |
if (cl == RUN) |
|---|
| 74 |
runfailed ~= c.toString; |
|---|
| 75 |
} |
|---|
| 76 |
else { |
|---|
| 77 |
if (cl == NORUN) |
|---|
| 78 |
norunfailed ~= c.toString; |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
else { |
|---|
| 82 |
if (cl == NOCOMPILE) |
|---|
| 83 |
nocompilefailed ~= c.toString; |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
size_t nerrors = 0; |
|---|
| 88 |
|
|---|
| 89 |
if (compilefailed.length > 0) |
|---|
| 90 |
{ |
|---|
| 91 |
Stdout.formatln("{}{}{}{}", compilefailed.length, '/', contents.files, " of the tests failed to compile:"); |
|---|
| 92 |
foreach(b; compilefailed) { |
|---|
| 93 |
Stdout.formatln(" {}",b); |
|---|
| 94 |
} |
|---|
| 95 |
nerrors += compilefailed.length; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
if (nocompilefailed.length > 0) |
|---|
| 99 |
{ |
|---|
| 100 |
Stdout.formatln("{}{}{}{}", nocompilefailed.length, '/', contents.files, " of the tests failed to NOT compile:"); |
|---|
| 101 |
foreach(b; nocompilefailed) { |
|---|
| 102 |
Stdout.formatln(" {}",b); |
|---|
| 103 |
} |
|---|
| 104 |
nerrors += nocompilefailed.length; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if (runfailed.length > 0) |
|---|
| 108 |
{ |
|---|
| 109 |
Stdout.formatln("{}{}{}{}", runfailed.length, '/', contents.files, " of the tests failed to run:"); |
|---|
| 110 |
foreach(b; runfailed) { |
|---|
| 111 |
Stdout.formatln(" {}",b); |
|---|
| 112 |
} |
|---|
| 113 |
nerrors += runfailed.length; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
if (norunfailed.length > 0) |
|---|
| 117 |
{ |
|---|
| 118 |
Stdout.formatln("{}{}{}{}", norunfailed.length, '/', contents.files, " of the tests failed to NOT run:"); |
|---|
| 119 |
foreach(b; norunfailed) { |
|---|
| 120 |
Stdout.formatln(" {}",b); |
|---|
| 121 |
} |
|---|
| 122 |
nerrors += norunfailed.length; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
Stdout.formatln("{}{}{}{}", contents.files - nerrors, '/', contents.files, " of the tests passed"); |
|---|
| 126 |
|
|---|
| 127 |
return nerrors ? 1 : 0; |
|---|
| 128 |
} |
|---|