1 module tests.it.buildgen;
2 
3 
4 public import tests.it;
5 import tests.utils;
6 import reggae.path: buildPath;
7 
8 
9 private string projectToModule(in string project) {
10     return project ~ ".reggaefile";
11 }
12 
13 void generateBuild(string project)(in string backend, string[] args = []) {
14     enum module_ = projectToModule(project);
15     auto options = testProjectOptions!module_(backend);
16     prepareTestBuild!module_(options);
17 
18     // binary backend doesn't need to generate anything
19     if(options.backend != Backend.binary) {
20         auto cmdArgs = buildCmd(options, args);
21         doBuildFor!module_(options, cmdArgs);
22     }
23 }
24 
25 
26 // runs ninja, make, etc. in an integraton test
27 void shouldBuild(string project)(string[] args = [],
28                                  string file = __FILE__,
29                                  size_t line = __LINE__ ) {
30     import reggae.config;
31     enum module_ = projectToModule(project);
32     buildCmdShouldRunOk!module_(options, args, file, line);
33 }
34 
35 
36 // runs a command in the test sandbox, throws if it fails,
37 // returns the output
38 auto shouldSucceed(string[] args, string file = __FILE__, size_t line = __LINE__) {
39     import reggae.config;
40     return shouldExecuteOk(buildPath(options.workingDir, args[0]) ~ args[1..$],
41                            options, file, line);
42 }
43 
44 auto shouldSucceed(string arg, string file = __FILE__, size_t line = __LINE__) {
45     return shouldSucceed([arg], file, line);
46 }
47 
48 
49 // runs a command in the test sandbox, throws if it succeeds
50 void shouldFail(T)(T args, string file = __FILE__, size_t line = __LINE__) {
51     import reggae.config;
52     shouldFailToExecute(args, options.workingDir, file, line);
53 }
54 
55 
56 // read a file in the test sandbox and verify its contents
57 void shouldEqualLines(string fileName, string[] lines,
58                       string file = __FILE__, size_t line = __LINE__) {
59     import reggae.config;
60     import std.ascii: newline;
61     import std.file: readText;
62     import std..string: chomp, split;
63 
64     readText(buildPath(options.workingDir, fileName)).chomp.split(newline)
65         .shouldEqual(lines, file, line);
66 }