1 module tests.dub_json;
2 
3 
4 import unit_threaded;
5 import reggae;
6 import reggae.dub.json;
7 
8 
9 auto jsonString =
10     `{`
11     `  "packages": [`
12     `    {`
13     `      "targetType": "executable",`
14     `      "path": "/path/to/pkg1",`
15     `      "name": "pkg1",`
16     `      "mainSourceFile": "src/boooo.d",`
17     `      "targetFileName": "super_app",`
18     `      "dflags": [],`
19     `      "versions": ["v1", "v2"],`
20     `      "dependencies": ["pkg_other"],`
21     `      "importPaths": ["leimports"],`
22     `      "stringImportPaths": [`
23     `        "src/string_imports",`
24     `        "src/moar_stringies"`
25     `      ],`
26     `      "files": [`
27     `        {`
28     `          "path": "src/foo.d",`
29     `          "type": "source",`
30     `          "active": true`
31     `        },`
32     `        {`
33     `          "path": "src/bar.d",`
34     `          "type": "source",`
35     `          "active": true`
36     `        },`
37     `        {`
38     `          "path": "src/boooo.d",`
39     `          "type": "source",`
40     `          "active": true`
41     `        }`
42     `      ]`
43     `    },`
44     `    {`
45     `      "path": "/weird/path/pkg_other",`
46     `      "name": "pkg_other",`
47     `      "importPaths": [`
48     `        "my_imports",`
49     `        "moar_imports"`
50     `      ],`
51     `      "dflags": [`
52     `        "-g", "-debug"`
53     `      ],`
54     `      "libs": ["liblib", "otherlib"],`
55     `      "versions": ["v3", "v4"],`
56     `      "stringImportPaths": [],`
57     `      "files": [`
58     `        {`
59     `          "path": "source/toto.d",`
60     `          "type": "source",`
61     `          "active": true`
62     `        },`
63     `        {`
64     `          "path": "source/africa.d",`
65     `          "type": "source",`
66     `          "active": true`
67     `        },`
68     `        {`
69     `          "path": "source/africa.d",`
70     `          "type": "weirdo",`
71     `          "active": true`
72     `        }`
73     `      ]`
74     `    }`
75     `  ]`
76     `}`;
77 
78 
79 void testJsonToDubDescribe() {
80     const info = getDubInfo(jsonString.dup);
81     info.shouldEqual(
82         DubInfo(
83             [DubPackage("pkg1", "/path/to/pkg1", "src/boooo.d", "super_app",
84                         [],
85                         ["leimports"],
86                         ["src/string_imports", "src/moar_stringies"],
87                         ["src/foo.d", "src/bar.d", "src/boooo.d"],
88                         "executable", ["v1", "v2"], ["pkg_other"]),
89 
90              DubPackage("pkg_other", "/weird/path/pkg_other", "", "",
91                         ["-g", "-debug"],
92                         ["my_imports", "moar_imports"],
93                         [],
94                         ["source/toto.d", "source/africa.d"],
95                         "", ["v3", "v4"], [], ["liblib", "otherlib"])]));
96 }
97 
98 
99 @ShouldFail("old command style")
100 void testDubInfoToTargets() {
101     const info = getDubInfo(jsonString.dup);
102     info.toTargets.shouldEqual(
103         [Target("path/to/pkg1/src/foo.o",
104                 "_dcompile "
105                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
106                 "-I/weird/path/pkg_other/moar_imports "
107                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
108                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
109                 [Target("/path/to/pkg1/src/foo.d")]),
110          Target("path/to/pkg1/src/bar.o",
111                 "_dcompile "
112                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
113                 "-I/weird/path/pkg_other/moar_imports "
114                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
115                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
116                 [Target("/path/to/pkg1/src/bar.d")]),
117          Target("path/to/pkg1/src/boooo.o",
118                 "_dcompile "
119                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
120                 "-I/weird/path/pkg_other/moar_imports "
121                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
122                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
123                 [Target("/path/to/pkg1/src/boooo.d")]),
124          Target("weird/path/pkg_other/source/toto.o",
125                 "_dcompile "
126                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
127                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
128                 [Target("/weird/path/pkg_other/source/toto.d")]),
129          Target("weird/path/pkg_other/source/africa.o",
130                 "_dcompile "
131                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
132                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
133                 [Target("/weird/path/pkg_other/source/africa.d")]),
134             ]);
135 
136     info.toTargets(No.main).shouldEqual(
137         [Target("path/to/pkg1/src/foo.o",
138                 "_dcompile "
139                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
140                 "-I/weird/path/pkg_other/moar_imports "
141                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
142                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
143                 [Target("/path/to/pkg1/src/foo.d")]),
144          Target("path/to/pkg1/src/bar.o",
145                 "_dcompile "
146                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
147                 "-I/weird/path/pkg_other/moar_imports "
148                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
149                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
150                 [Target("/path/to/pkg1/src/bar.d")]),
151          Target("weird/path/pkg_other/source/toto.o",
152                 "_dcompile "
153                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
154                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
155                 [Target("/weird/path/pkg_other/source/toto.d")]),
156          Target("weird/path/pkg_other/source/africa.o",
157                 "_dcompile "
158                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
159                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
160                 [Target("/weird/path/pkg_other/source/africa.d")]),
161             ]);
162 }
163 
164 
165 @ShouldFail("old command style")
166 void testDubInfoToTargetsLib() {
167     const info = getDubInfo(jsonString.replace("executable", "library"));
168     info.mainTarget.shouldEqual(
169         Target("super_app", "_link flags=-lib,-L-lliblib,-L-lotherlib",
170                [Target("path/to/pkg1/src/foo.o",
171                        "_dcompile "
172                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
173                        "-I/weird/path/pkg_other/moar_imports "
174                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
175                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
176                        [Target("/path/to/pkg1/src/foo.d")]),
177                 Target("path/to/pkg1/src/bar.o",
178                        "_dcompile "
179                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
180                        "-I/weird/path/pkg_other/moar_imports "
181                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
182                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
183                        [Target("/path/to/pkg1/src/bar.d")]),
184                 Target("path/to/pkg1/src/boooo.o",
185                        "_dcompile "
186                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
187                        "-I/weird/path/pkg_other/moar_imports "
188                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
189                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
190                        [Target("/path/to/pkg1/src/boooo.d")]),
191                 Target("weird/path/pkg_other/source/toto.o",
192                        "_dcompile "
193                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
194                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
195                        [Target("/weird/path/pkg_other/source/toto.d")]),
196                 Target("weird/path/pkg_other/source/africa.o",
197                        "_dcompile "
198                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
199                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
200                        [Target("/weird/path/pkg_other/source/africa.d")]),
201                    ]));
202 }
203 
204 
205 @ShouldFail("old command style")
206 void testDubInfoWithLibs() {
207     const info = getDubInfo(jsonString.dup);
208     info.mainTarget.shouldEqual(
209         Target("super_app", "_link flags=-L-lliblib,-L-lotherlib",
210                [Target("path/to/pkg1/src/foo.o",
211                        "_dcompile "
212                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
213                        "-I/weird/path/pkg_other/moar_imports "
214                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
215                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
216                        [Target("/path/to/pkg1/src/foo.d")]),
217                 Target("path/to/pkg1/src/bar.o",
218                        "_dcompile "
219                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
220                        "-I/weird/path/pkg_other/moar_imports "
221                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
222                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
223                        [Target("/path/to/pkg1/src/bar.d")]),
224                 Target("path/to/pkg1/src/boooo.o",
225                        "_dcompile "
226                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
227                        "-I/weird/path/pkg_other/moar_imports "
228                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
229                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
230                        [Target("/path/to/pkg1/src/boooo.d")]),
231                 Target("weird/path/pkg_other/source/toto.o",
232                        "_dcompile "
233                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
234                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
235                        [Target("/weird/path/pkg_other/source/toto.d")]),
236                 Target("weird/path/pkg_other/source/africa.o",
237                        "_dcompile "
238                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
239                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
240                        [Target("/weird/path/pkg_other/source/africa.d")]),
241                    ]));
242 }
243 
244 
245 void testDubFetch() {
246     const info = getDubInfo(jsonString.dup);
247     info.fetchCommands.shouldEqual(
248         [["dub", "fetch", "pkg_other"]]);
249 }