-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathswift-versions.test.ts
92 lines (77 loc) · 2.3 KB
/
swift-versions.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { OS, System } from "../src/os";
import * as versions from "../src/swift-versions";
const macOS: System = {
os: OS.MacOS,
version: "latest",
name: "macOS",
arch: "arm64",
};
const ubuntu: System = {
os: OS.Ubuntu,
version: "latest",
name: "Ubuntu",
arch: "x64",
};
const windows: System = {
os: OS.Windows,
version: "latest",
name: "Windows",
arch: "x64",
};
describe("swift version resolver", () => {
it("identifies X.X.X versions", async () => {
const version = await versions.verify("5.0.1", macOS);
expect(version).toBe("5.0.1");
});
it("identifies X.X.0 versions", async () => {
const version = await versions.verify("5.0.0", macOS);
expect(version).toBe("5.0");
});
it("identifies X.X versions", async () => {
const version = await versions.verify("5.0", macOS);
expect(version).toBe("5.0.1");
});
it("identifies ~X.X versions", async () => {
const version = await versions.verify("~5.0", macOS);
expect(version).toBe("5.0.1");
});
it("identifies X versions", async () => {
const version = await versions.verify("5", macOS);
expect(version).toBe("5.10.1");
});
it("identifies versions based on system", async () => {
const macVersion = await versions.verify("5.0", macOS);
expect(macVersion).toBe("5.0.1");
const ubuntuVersion = await versions.verify("5.0", ubuntu);
expect(ubuntuVersion).toBe("5.0.3");
});
it("throws an error if the version isn't available for the system", async () => {
expect.assertions(2);
try {
await versions.verify("5.0.3", macOS);
} catch (e) {
expect(e).toEqual(new Error('Version "5.0.3" is not available'));
}
try {
await versions.verify("5.2", windows);
} catch (e) {
expect(e).toEqual(new Error('Version "5.2" is not available'));
}
});
it("throws an error if version is invalid", async () => {
expect.assertions(1);
try {
await versions.verify("foo", macOS);
} catch (e) {
expect(e).toEqual(new Error("Version must be a valid semver format."));
}
});
it("throws an error if no matching version is found", async () => {
expect.assertions(1);
try {
await versions.verify("1.0", macOS);
} catch (e) {
expect(e).toEqual(new Error('Version "1.0" is not available'));
}
});
});