Skip to content

Commit

Permalink
Fix 4.2 compile and support running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
finestructure committed Sep 2, 2020
1 parent 6d4fda6 commit f37bd4f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
30 changes: 30 additions & 0 deletions Sources/SemanticVersion/SemanticVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ extension SemanticVersion {

// Source: https://regex101.com/r/Ly7O1x/3/
// Linked from https://semver.org
#if swift(>=5)

let semVerRegex = NSRegularExpression(#"""
^
v? # SPI extension: allow leading 'v'
Expand All @@ -91,3 +93,31 @@ v? # SPI extension: allow leading 'v'
)?
$
"""#, options: [.allowCommentsAndWhitespace])

#else

let semVerRegex = NSRegularExpression("""
^
v? # SPI extension: allow leading 'v'
(?<major>0|[1-9]\\d*)
\\.
(?<minor>0|[1-9]\\d*)
\\.
(?<patch>0|[1-9]\\d*)
(?:-
(?<prerelease>
(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)
(?:\\.
(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)
)
*)
)?
(?:\\+
(?<buildmetadata>[0-9a-zA-Z-]+
(?:\\.[0-9a-zA-Z-]+)
*)
)?
$
""", options: [.allowCommentsAndWhitespace])

#endif
36 changes: 28 additions & 8 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
//
// File.swift
//
//
// Created by Sven A. Schmidt on 01/09/2020.
//

import Foundation
#if swift(>=5)

#else

import XCTest

@testable import SemanticVersionTests

extension SemanticVersionTests {
static var allTests: [(String, (SemanticVersionTests) -> () throws -> Void)] = [
("test_semVerRegex_valid", test_semVerRegex_valid),
("test_allow_leading_v", test_allow_leading_v),
("test_semVerRegex_invalid", test_semVerRegex_invalid),
("test_init", test_init),
("test_description", test_description),
("test_Comparable", test_Comparable),
("test_isStable", test_isStable),
("test_isMajorRelease", test_isMajorRelease),
("test_isMinorRelease", test_isMinorRelease),
("test_isPatchRelease", test_isPatchRelease),
]
}

XCTMain([
testCase(SemanticVersionTests.allTests)
])

#endif

0 comments on commit f37bd4f

Please sign in to comment.