1 module tests.dub_describe;
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 void testDubInfoToTargets() {
100     const info = getDubInfo(jsonString.dup);
101     info.toTargets.shouldEqual(
102         [Target("path/to/pkg1/src/foo.o",
103                 "_dcompile  "
104                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
105                 "-I/weird/path/pkg_other/moar_imports "
106                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
107                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
108                 [Target("/path/to/pkg1/src/foo.d")]),
109          Target("path/to/pkg1/src/bar.o",
110                 "_dcompile  "
111                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
112                 "-I/weird/path/pkg_other/moar_imports "
113                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
114                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
115                 [Target("/path/to/pkg1/src/bar.d")]),
116          Target("path/to/pkg1/src/boooo.o",
117                 "_dcompile  "
118                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
119                 "-I/weird/path/pkg_other/moar_imports "
120                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
121                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
122                 [Target("/path/to/pkg1/src/boooo.d")]),
123          Target("weird/path/pkg_other/source/toto.o",
124                 "_dcompile  "
125                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
126                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
127                 [Target("/weird/path/pkg_other/source/toto.d")]),
128          Target("weird/path/pkg_other/source/africa.o",
129                 "_dcompile  "
130                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
131                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
132                 [Target("/weird/path/pkg_other/source/africa.d")]),
133             ]);
134 
135     info.toTargets(No.main).shouldEqual(
136         [Target("path/to/pkg1/src/foo.o",
137                 "_dcompile  "
138                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
139                 "-I/weird/path/pkg_other/moar_imports "
140                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
141                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
142                 [Target("/path/to/pkg1/src/foo.d")]),
143          Target("path/to/pkg1/src/bar.o",
144                 "_dcompile  "
145                 "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
146                 "-I/weird/path/pkg_other/moar_imports "
147                 "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
148                 "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
149                 [Target("/path/to/pkg1/src/bar.d")]),
150          Target("weird/path/pkg_other/source/toto.o",
151                 "_dcompile  "
152                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
153                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
154                 [Target("/weird/path/pkg_other/source/toto.d")]),
155          Target("weird/path/pkg_other/source/africa.o",
156                 "_dcompile  "
157                 "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
158                 "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
159                 [Target("/weird/path/pkg_other/source/africa.d")]),
160             ]);
161 }
162 
163 
164 void testDubInfoToTargetsLib() {
165     const info = getDubInfo(jsonString.replace("executable", "library"));
166     info.mainTarget.shouldEqual(
167         Target("super_app", "_dlink flags=-lib,-L-lliblib,-L-lotherlib",
168                [Target("path/to/pkg1/src/foo.o",
169                        "_dcompile  "
170                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
171                        "-I/weird/path/pkg_other/moar_imports "
172                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
173                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
174                        [Target("/path/to/pkg1/src/foo.d")]),
175                 Target("path/to/pkg1/src/bar.o",
176                        "_dcompile  "
177                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
178                        "-I/weird/path/pkg_other/moar_imports "
179                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
180                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
181                        [Target("/path/to/pkg1/src/bar.d")]),
182                 Target("path/to/pkg1/src/boooo.o",
183                        "_dcompile  "
184                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
185                        "-I/weird/path/pkg_other/moar_imports "
186                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
187                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
188                        [Target("/path/to/pkg1/src/boooo.d")]),
189                 Target("weird/path/pkg_other/source/toto.o",
190                        "_dcompile  "
191                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
192                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
193                        [Target("/weird/path/pkg_other/source/toto.d")]),
194                 Target("weird/path/pkg_other/source/africa.o",
195                        "_dcompile  "
196                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
197                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
198                        [Target("/weird/path/pkg_other/source/africa.d")]),
199                    ]));
200 }
201 
202 
203 void testDubInfoWithLibs() {
204     const info = getDubInfo(jsonString.dup);
205     info.mainTarget.shouldEqual(
206         Target("super_app", "_dlink flags=-L-lliblib,-L-lotherlib",
207                [Target("path/to/pkg1/src/foo.o",
208                        "_dcompile  "
209                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
210                        "-I/weird/path/pkg_other/moar_imports "
211                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
212                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
213                        [Target("/path/to/pkg1/src/foo.d")]),
214                 Target("path/to/pkg1/src/bar.o",
215                        "_dcompile  "
216                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
217                        "-I/weird/path/pkg_other/moar_imports "
218                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
219                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
220                        [Target("/path/to/pkg1/src/bar.d")]),
221                 Target("path/to/pkg1/src/boooo.o",
222                        "_dcompile  "
223                        "includes=-I/path/to/pkg1/leimports,-I/weird/path/pkg_other/my_imports,"
224                        "-I/weird/path/pkg_other/moar_imports "
225                        "flags=-version=v1,-version=v2,-version=v3,-version=v4 "
226                        "stringImports=-J/path/to/pkg1/src/string_imports,-J/path/to/pkg1/src/moar_stringies",
227                        [Target("/path/to/pkg1/src/boooo.d")]),
228                 Target("weird/path/pkg_other/source/toto.o",
229                        "_dcompile  "
230                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
231                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
232                        [Target("/weird/path/pkg_other/source/toto.d")]),
233                 Target("weird/path/pkg_other/source/africa.o",
234                        "_dcompile  "
235                        "includes=-I/weird/path/pkg_other/my_imports,-I/weird/path/pkg_other/moar_imports "
236                        "flags=-g,-debug,-version=v3,-version=v4 stringImports=",
237                        [Target("/weird/path/pkg_other/source/africa.d")]),
238                    ]));
239 }
240 
241 
242 void testDubFetch() {
243     const info = getDubInfo(jsonString.dup);
244     info.fetchCommands.shouldEqual(
245         [["dub", "fetch", "pkg_other"]]);
246 }