2018-11-11 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libphobos / testsuite / test_runner.d
blobc9a908ae1460f4918db2fed9ab67c3d7405b5ba8
1 import core.runtime, core.time : MonoTime;
2 import core.stdc.stdio;
4 ModuleInfo* getModuleInfo(string name)
6 foreach (m; ModuleInfo)
7 if (m.name == name) return m;
8 assert(0, "module '"~name~"' not found");
11 bool tester()
13 return Runtime.args.length > 1 ? testModules() : printAll();
16 string mode;
19 bool testModules()
21 bool ret = true;
22 foreach(name; Runtime.args[1..$])
24 immutable pkg = ".package";
25 immutable pkgLen = pkg.length;
27 if (name.length > pkgLen && name[$ - pkgLen .. $] == pkg)
28 name = name[0 .. $ - pkgLen];
30 doTest(getModuleInfo(name), ret);
33 return ret;
36 bool printAll()
38 foreach (m; ModuleInfo)
40 if (m.unitTest)
42 string name = m.name;
43 printf("%.*s\n", cast(int)name.length, name.ptr);
46 return true;
50 void doTest(ModuleInfo* moduleInfo, ref bool ret)
52 if (auto fp = moduleInfo.unitTest)
54 auto name = moduleInfo.name;
55 try
57 immutable t0 = MonoTime.currTime;
58 fp();
59 printf("%.3fs PASS %.*s %.*s\n",
60 (MonoTime.currTime - t0).total!"msecs" / 1000.0,
61 cast(uint)mode.length, mode.ptr,
62 cast(uint)name.length, name.ptr);
64 catch (Throwable e)
66 auto msg = e.toString();
67 printf("****** FAIL %.*s %.*s\n%.*s\n",
68 cast(uint)mode.length, mode.ptr,
69 cast(uint)name.length, name.ptr,
70 cast(uint)msg.length, msg.ptr);
71 ret = false;
77 shared static this()
79 version(D_Coverage)
81 import core.runtime : dmd_coverSetMerge;
82 dmd_coverSetMerge(true);
84 Runtime.moduleUnitTester = &tester;
86 debug mode = "debug";
87 else mode = "release";
88 static if ((void*).sizeof == 4) mode ~= "32";
89 else static if ((void*).sizeof == 8) mode ~= "64";
90 else static assert(0, "You must be from the future!");
93 void main()