File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1+ import { versionFromString } from "../src/get-version" ;
2+
3+ describe ( "version lookup" , ( ) => {
4+ it ( "identifies version from swift version" , async ( ) => {
5+ const version = versionFromString (
6+ "Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)"
7+ ) ;
8+ expect ( version ) . toBe ( "5.4.2" ) ;
9+ } ) ;
10+
11+ it ( "identifies version from swift version with target" , async ( ) => {
12+ const version = versionFromString (
13+ `Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)
14+ Target: x86_64-apple-macosx11.0`
15+ ) ;
16+ expect ( version ) . toBe ( "5.5" ) ;
17+ } ) ;
18+
19+ it ( "identifies version from swift-driver version" , async ( ) => {
20+ const version = versionFromString (
21+ "swift-driver version: 1.26.9 Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)"
22+ ) ;
23+ expect ( version ) . toBe ( "5.5" ) ;
24+ } ) ;
25+ } ) ;
Original file line number Diff line number Diff line change @@ -20,11 +20,17 @@ export async function getVersion(
2020
2121 await exec ( command , args , options ) ;
2222
23- if ( error ) {
24- throw new Error ( error ) ;
23+ if ( ! output && error ) {
24+ throw new Error ( "Error getting swift version " + error ) ;
2525 }
2626
27- const match = output . match ( / (?< version > [ 0 - 9 ] + \. [ 0 - 9 + ] + ( \. [ 0 - 9 ] + ) ? ) / ) || {
27+ return versionFromString ( output ) ;
28+ }
29+
30+ export function versionFromString ( subject : string ) : string | null {
31+ const match = subject . match (
32+ / A p p l e \ S w i f t \ v e r s i o n (?< version > [ 0 - 9 ] + \. [ 0 - 9 + ] + ( \. [ 0 - 9 ] + ) ? ) /
33+ ) || {
2834 groups : { version : null } ,
2935 } ;
3036
You can’t perform that action at this time.
0 commit comments