Skip to content

Commit 64e7378

Browse files
committed
test both minimum and maximum libdparse version
1 parent d2362c9 commit 64e7378

File tree

2 files changed

+150
-2
lines changed

2 files changed

+150
-2
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ language: d
33
d:
44
- dmd
55
- ldc
6+
env:
7+
- VERSION=min
8+
- VERSION=max
69
script:
7-
- dub build --config=lib --compiler=$DC
8-
- dub build --config=exe --compiler=$DC
10+
- rdmd ./test_with_libdparse.d -- dub test --compiler=$DC
11+
- rdmd ./test_with_libdparse.d -- dub build --config=lib --compiler=$DC
12+
- rdmd ./test_with_libdparse.d -- dub build --config=exe --compiler=$DC

test_with_libdparse.d

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env rdmd
2+
3+
// Runs `dub test --compiler=$DC` with either the minimum available version on
4+
// DUB or the maximum available version on dub, respecting the dub.json version
5+
// range.
6+
//
7+
// Running with VERSION=min will use the lowest available version of a package,
8+
// for a version specification of format
9+
// "~>0.13.0" this will run with "0.13.0",
10+
// ">=0.13.0" this will run with "0.13.0",
11+
// ">=0.13.0 <0.15.0" this will run with "0.13.0"
12+
// otherwise error.
13+
//
14+
// Running with VERSION=max will use the highest available version of a package,
15+
// for a version specification of format
16+
// "~>0.13.0" this will run with "~>0.13.0",
17+
// ">=0.13.0" this will run with ">=0.13.0",
18+
// ">=0.13.0 <0.15.0" this will run with "<0.15.0"
19+
// otherwise error.
20+
//
21+
// By default this modifies the package "libdparse" but this can be modified by
22+
// specifying the $PACKAGE environment variable.
23+
//
24+
// Temporarily creates a dub.json file and renames the original to dub.1.json,
25+
// both of which is undone automatically on exit.
26+
//
27+
// dub upgrade will be run after creating the artificial dub.json and before
28+
// running the test command.
29+
//
30+
// If you run with `-- <command>` then that command will be run instead of
31+
// `dub test --compiler=$DC`
32+
//
33+
// The script returns 0 on success after all commands or 1 if anything fails.
34+
35+
import std;
36+
import fs = std.file;
37+
38+
int main(string[] args)
39+
{
40+
/// wanted target version (min or max)
41+
const ver = environment.get("VERSION", "max");
42+
/// package to modify and test
43+
const pkg = environment.get("PACKAGE", "libdparse");
44+
/// D compiler to use
45+
const dc = environment.get("DC", "dmd");
46+
47+
if (!ver.among!("min", "max"))
48+
{
49+
stderr.writefln("Unsupported version '%s', try min or max instead", ver);
50+
return 1;
51+
}
52+
53+
stderr.writeln("PACKAGE=", pkg);
54+
stderr.writeln("VERSION=", ver);
55+
stderr.writeln("DC=", dc);
56+
57+
auto json = parseJSON(readText("dub.json"));
58+
auto verSpec = json["dependencies"][pkg];
59+
if (verSpec.type != JSONType.string)
60+
{
61+
stderr.writefln("Unsupported dub.json version '%s' (should be string)",
62+
verSpec);
63+
return 1;
64+
}
65+
66+
// find the version range to use based on the dependency version and wanted
67+
// version target.
68+
string determined = resolveVersion(verSpec.str, ver);
69+
stderr.writefln("Testing using %s version %s.", pkg, determined);
70+
71+
json["dependencies"][pkg] = JSONValue(determined);
72+
73+
// backup dub.json to dub.1.json and restore on exit
74+
fs.rename("dub.json", "dub.1.json");
75+
scope (exit)
76+
fs.rename("dub.1.json", "dub.json");
77+
78+
// create dummy dub.json and delete on exit
79+
fs.write("dub.json", json.toPrettyString);
80+
scope (exit)
81+
fs.remove("dub.json");
82+
83+
stderr.writeln("$ dub upgrade");
84+
if (spawnShell("dub upgrade").wait != 0)
85+
return 1;
86+
87+
auto cmd = ["dub", "test", "--compiler=" ~ dc];
88+
auto cmdIndex = args.countUntil("--");
89+
if (cmdIndex != -1)
90+
cmd = args[cmdIndex + 1 .. $];
91+
92+
stderr.writefln("$ %(%s %)", cmd);
93+
if (spawnProcess(cmd).wait != 0)
94+
return 1;
95+
96+
return 0;
97+
}
98+
99+
string resolveVersion(string verRange, string wanted)
100+
{
101+
if (verRange.startsWith("~>"))
102+
{
103+
switch (wanted)
104+
{
105+
case "min":
106+
return verRange[2 .. $];
107+
case "max":
108+
return verRange;
109+
default:
110+
assert(false, "unknown target version " ~ wanted);
111+
}
112+
}
113+
else if (verRange.startsWith(">="))
114+
{
115+
auto end = verRange.indexOf("<");
116+
if (end == -1)
117+
{
118+
switch (wanted)
119+
{
120+
case "min":
121+
return verRange[2 .. $];
122+
case "max":
123+
return verRange;
124+
default:
125+
assert(false, "unknown target version " ~ wanted);
126+
}
127+
}
128+
else
129+
{
130+
switch (wanted)
131+
{
132+
case "min":
133+
return verRange[2 .. end].strip;
134+
case "max":
135+
return verRange[end .. $];
136+
default:
137+
assert(false, "unknown target version " ~ wanted);
138+
}
139+
}
140+
}
141+
else
142+
throw new Exception("Unsupported version range specifier to multi-test:"
143+
~ verRange);
144+
}

0 commit comments

Comments
 (0)