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