1 module tests.it.runtime.regressions;
2 
3 
4 import tests.it.runtime;
5 import reggae.reggae;
6 
7 
8 @("Issue 14: builddir not expanded")
9 @Tags(["ninja", "regressions", "posix"])
10 unittest {
11 
12     with(immutable ReggaeSandbox()) {
13         writeFile("reggaefile.d", q{
14             import reggae;
15             enum ao = objectFile(SourceFile("a.c"));
16             enum liba = Target("$builddir/liba.a", "ar rcs $out $in", [ao]);
17             mixin build!(liba);
18         });
19 
20         writeFile("a.c");
21 
22         runReggae("-b", "ninja");
23         ninja.shouldExecuteOk;
24     }
25 }
26 
27 @("Issue 12: can't set executable as a dependency")
28 @Tags(["ninja", "regressions"])
29 unittest {
30 
31     with(immutable ReggaeSandbox()) {
32         writeFile("reggaefile.d", q{
33             import reggae;
34             alias app = scriptlike!(App(SourceFileName("main.d"),
35                                         BinaryFileName("$builddir/myapp")),
36                                         Flags(),
37                                         ImportPaths(["/path/to/imports"])
38                     );
39             alias code_gen = target!("out.c", "./myapp $in $out", target!"in.txt", app);
40             mixin build!(code_gen);
41         });
42 
43         writeFile("main.d", q{
44             import std.stdio;
45             import std.algorithm;
46             import std.conv;
47             void main(string[] args) {
48                 auto inFileName = args[1];
49                 auto outFileName = args[2];
50                 auto lines = File(inFileName, `r`).byLine.
51                     map!(a => a.to!string).
52                     map!(a => a ~ ` ` ~ a);
53                 auto outFile = File(outFileName, `w`);
54                 foreach(line; lines) outFile.writeln(line);
55             }
56         });
57 
58         writeFile("in.txt", ["foo", "bar", "baz"]);
59 
60         runReggae("-b", "ninja");
61         ninja.shouldExecuteOk;
62         ["cat", "out.c"].shouldExecuteOk;
63         shouldEqualLines("out.c",
64                          ["foo foo",
65                           "bar bar",
66                           "baz baz"]);
67     }
68 }
69 
70 
71 @("Issue 10: dubConfigurationTarget doesn't work for unittest builds")
72 @Tags(["ninja", "regressions"])
73 unittest {
74     import reggae.path: buildPath;
75     import std.file;
76 
77     with(immutable ReggaeSandbox()) {
78 
79         writeFile("dub.json", `
80             {
81                 "name": "dubproj",
82                 "configurations": [
83                     { "name": "executable", "targetName": "foo"},
84                     { "name": "unittest", "targetName": "ut"}
85               ]
86             }`);
87 
88         writeFile("reggaefile.d", q{
89             import reggae;
90             alias ut = dubConfigurationTarget!(Configuration(`unittest`),
91                                                CompilerFlags(`-g -debug -cov`));
92             mixin build!ut;
93         });
94 
95         mkdir(buildPath(testPath, "source"));
96         writeFile(buildPath("source/src.d"), q{
97             unittest { static assert(false, `oopsie`); }
98             int add(int i, int j) { return i + j; }
99         });
100 
101         writeFile(buildPath("source/main.d"), q{
102             import src;
103             void main() {}
104         });
105 
106         runReggae("-b", "ninja");
107         ninja.shouldFailToExecute(testPath);
108     }
109 }