Skip to content

Commit

Permalink
Improved version lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
fwal committed Oct 22, 2021
1 parent 6efa2ef commit 798bbec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions __tests__/get-version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { versionFromString } from "../src/get-version";

describe("version lookup", () => {
it("identifies version from swift version", async () => {
const version = versionFromString(
"Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)"
);
expect(version).toBe("5.4.2");
});

it("identifies version from swift-driver version", async () => {
const version = versionFromString(
"swift-driver version: 1.26.9 Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)"
);
expect(version).toBe("5.5");
});
});
8 changes: 7 additions & 1 deletion src/get-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export async function getVersion(
throw new Error(error);
}

const match = output.match(/(?<version>[0-9]+\.[0-9+]+(\.[0-9]+)?)/) || {
return versionFromString(output);
}

export function versionFromString(subject: string): string | null {
const match = subject.match(
/Apple\ Swift\ version (?<version>[0-9]+\.[0-9+]+(\.[0-9]+)?)/
) || {
groups: { version: null },
};

Expand Down

0 comments on commit 798bbec

Please sign in to comment.