1 /**
2   As a reggae user
3   I want to be able to write build descriptions in Python
4   So I don't have to compile the build description
5  */
6 
7 module tests.it.runtime.python;
8 
9 import tests.it.runtime;
10 
11 @("Build description")
12 @Tags(["ninja", "json_build", "python"])
13 unittest {
14     with(immutable ReggaeSandbox()) {
15         writeFile("reggaefile.py",
16                   [`from reggae import *`,
17                    `b = Build(executable(name='app', src_dirs=['src']))`]);
18         writeHelloWorldApp;
19 
20         runReggae("-b", "ninja");
21         ninja.shouldExecuteOk;
22         shouldSucceed("app").shouldEqual(["Hello world!"]);
23     }
24 }
25 
26 @("User variables")
27 @Tags(["ninja", "json_build", "python"])
28 unittest {
29     with(immutable ReggaeSandbox()) {
30         writeFile("reggaefile.py",
31                   [`from reggae import *`,
32                    `name = user_vars.get('name', 'app')`,
33                    `b = Build(executable(name=name, src_dirs=['src']))`]);
34         writeHelloWorldApp;
35 
36         runReggae("-b", "ninja", "-dname=foo");
37         ninja.shouldExecuteOk;
38         shouldSucceed("foo").shouldEqual(["Hello world!"]);
39     }
40 }
41 
42 @("default options")
43 @Tags(["ninja", "json_build", "python"])
44 unittest {
45     with(immutable ReggaeSandbox()) {
46         writeFile("reggaefile.py",
47                   [`from reggae import *`,
48                    `opts = DefaultOptions(dCompiler='nope')`,
49                    `b = Build(executable(name='app', src_dirs=['src']))`]);
50         writeHelloWorldApp;
51 
52         runReggae("-b", "ninja");
53         // there's no binary named "nope" so the build fails
54         ninja.shouldFailToExecute(testPath);
55     }
56 }
57 
58 @("Multiple runs will not crash")
59 @Tags(["ninja", "json_build", "python"])
60 unittest {
61     with(immutable ReggaeSandbox()) {
62         writeFile("reggaefile.py",
63                 [`from reggae import *`,
64                  `b = Build(executable(name='app', src_dirs=['src']))`]);
65         writeHelloWorldApp;
66 
67         runReggae("-b", "ninja", "-d", "foo=bar");
68         runReggae("-b", "ninja", "-d", "foo=baz");
69     }
70 }