Skip to content

Commit 6caa27e

Browse files
authored
Move test suite to Swift Testing (#7)
* Move test suite to Swift Testing * Patch credential leak * Swift 6 prep * Tweak for Linux Swift 6 breakage * Rebuild docs
1 parent a1535a9 commit 6caa27e

36 files changed

+3063
-738
lines changed

.github/workflows/test.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ jobs:
1313
name: Linux SPM unit tests
1414
runs-on: ubuntu-latest
1515
container:
16-
image: swift:5.10
16+
image: swift:6.0
1717
steps:
1818
- uses: actions/checkout@v4
19+
with:
20+
persist-credentials: false
1921
- name: Run tests
2022
run: swift test
2123

@@ -25,8 +27,10 @@ jobs:
2527
steps:
2628
- uses: maxim-lobanov/setup-xcode@v1
2729
with:
28-
xcode-version: '16.0-beta'
30+
xcode-version: '16.0'
2931
- uses: actions/checkout@v4
32+
with:
33+
persist-credentials: false
3034
- name: SPM tests
3135
run: make test
3236
- name: Normalize coverage info
@@ -43,8 +47,10 @@ jobs:
4347
steps:
4448
- uses: compnerd/gha-setup-swift@main
4549
with:
46-
branch: swift-5.10-release
47-
tag: 5.10-RELEASE
50+
branch: swift-6.0-release
51+
tag: 6.0-RELEASE
4852
- uses: actions/checkout@v4
53+
with:
54+
persist-credentials: false
4955
- name: Run tests
5056
run: swift test -v --enable-test-discovery

.jazzy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ theme: fw2020
1414
deployment_url: https://johnfairh.github.io/SourceMapper/
1515
build_tool: spm
1616
modules: SourceMapper
17-
module_version: v2.0.0
17+
module_version: v3.0.0
1818
custom_groups:
1919
- name: Types
2020
children:

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ test:
1313
swift test --enable-code-coverage
1414

1515
test_linux:
16-
docker run -v `pwd`:`pwd` -w `pwd` --name SourceMapper --rm swift:5.7 swift test
16+
docker run -v `pwd`:`pwd` -w `pwd` --name SourceMapper --rm swift:6.0 swift test
1717

1818
shell_linux:
19-
docker run -it -v `pwd`:`pwd` -w `pwd` --name SourceMapper --rm swift:5.7 /bin/bash
19+
docker run -it -v `pwd`:`pwd` -w `pwd` --name SourceMapper --rm swift:6.0 /bin/bash
2020

2121
install: build
2222
-mkdir -p ${PREFIX}/bin

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ No support for:
4343

4444
## Requirements
4545

46-
* Swift 5.7
47-
* macOS 10.10 (tested on macOS 12.0 IA64)
46+
* Swift 6.0
47+
* macOS 14 (tested on macOS 14.6.1 IA64)
4848
* Linux (tested on Ubuntu 18.04.5)
49-
* Windows 10, Swift 5.7 (tested in CI only)
49+
* Windows 10, Swift 6.0 (tested in CI only)
5050

5151
## Installation
5252

@@ -56,7 +56,7 @@ Package dependency:
5656
```swift
5757
.package(name: "SourceMapper",
5858
url: "https://github.com/johnfairh/SourceMapper.git",
59-
from: "2.0.0")
59+
from: "3.0.0")
6060
```
6161

6262
## Contributions

Sources/Cli/main.swift

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
//
77

88
import SourceMapper
9+
10+
#if canImport(Glibc)
11+
@preconcurrency import Glibc
12+
#endif
913
import Foundation
1014

1115
let args = ProcessInfo.processInfo.arguments

Tests/SourceMapperTests/TestBasics.swift

+45-38
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,63 @@
66
//
77

88
@testable import SourceMapper
9-
import XCTest
9+
import Testing
10+
import Foundation
11+
12+
extension Tag {
13+
@Tag static var basics: Self
14+
}
1015

1116
/// Basic flows of the use cases
12-
class TestBasics: XCTestCase {
17+
@Suite(.tags(.basics))
18+
final class TestBasics {
19+
@Test
1320
func testEmptyRoundTrip() throws {
1421
let empty = SourceMap()
1522
let serialized = try empty.encode()
1623
let deserialized = try SourceMap(serialized)
17-
XCTAssertEqual(empty, deserialized)
18-
try XCTAssertEqual(empty.encodeString(), deserialized.encodeString())
24+
#expect(empty == deserialized)
25+
#expect(try empty.encodeString() == deserialized.encodeString())
1926
}
2027

21-
func testLoading() throws {
22-
let files = ["jazzy.css.map.dart", "jazzy.css.map.libsass"]
23-
try files.forEach { fixtureName in
24-
let map = try SourceMap(fixtureName: fixtureName)
25-
XCTAssertEqual(SourceMap.VERSION, map.version)
26-
let file = try XCTUnwrap(map.file)
27-
XCTAssertEqual(fixtureName.replacingOccurrences(of: ".map", with: ""), file)
28-
XCTAssertEqual(1, map.sources.count)
29-
XCTAssertTrue(map.sources[0].url.hasSuffix("jazzy.css.scss"))
28+
@Test(arguments: ["jazzy.css.map.dart", "jazzy.css.map.libsass"])
29+
func testLoading(fixtureName: String) throws {
30+
let map = try SourceMap(fixtureName: fixtureName)
31+
#expect(map.version == SourceMap.VERSION)
32+
let file = try #require(map.file)
33+
#expect(file == fixtureName.replacingOccurrences(of: ".map", with: ""))
34+
#expect(map.sources.count == 1)
35+
#expect(map.sources[0].url.hasSuffix("jazzy.css.scss"))
3036

31-
print(map)
32-
let unpackedMap = try UnpackedSourceMap(map)
33-
print(unpackedMap.segmentsDescription)
37+
print(map)
38+
let unpackedMap = try UnpackedSourceMap(map)
39+
print(unpackedMap.segmentsDescription)
3440

35-
// Check a couple of mapping positions, one towards the start and
36-
// one at the end to check the mapping accumulators.
41+
// Check a couple of mapping positions, one towards the start and
42+
// one at the end to check the mapping accumulators.
3743

38-
let mapped1 = try XCTUnwrap(unpackedMap.map(line: 26, column: 22))
39-
let pos1 = try XCTUnwrap(mapped1.sourcePos)
40-
XCTAssertEqual(25, pos1.line)
41-
XCTAssertTrue(pos1.column >= 14)
44+
let mapped1 = try #require(unpackedMap.map(line: 26, column: 22))
45+
let pos1 = try #require(mapped1.sourcePos)
46+
#expect(pos1.line == 25)
47+
#expect(pos1.column >= 14)
4248

43-
let mapped2 = try XCTUnwrap(unpackedMap.map(line: 465, column: 12))
44-
let pos2 = try XCTUnwrap(mapped2.sourcePos)
45-
XCTAssertEqual(601, pos2.line)
46-
XCTAssertTrue(pos2.column >= 4)
47-
}
49+
let mapped2 = try #require(unpackedMap.map(line: 465, column: 12))
50+
let pos2 = try #require(mapped2.sourcePos)
51+
#expect(pos2.line == 601)
52+
#expect(pos2.column >= 4)
4853
}
4954

55+
@Test
5056
func testPrinting() throws {
5157
var map = SourceMap()
52-
XCTAssertTrue(try UnpackedSourceMap(map).segmentsDescription.isEmpty)
53-
XCTAssertEqual(#"SourceMap(v=3 #sources=0 mappings="")"#, map.description)
58+
try #expect(UnpackedSourceMap(map).segmentsDescription.isEmpty)
59+
#expect(map.description == #"SourceMap(v=3 #sources=0 mappings="")"#)
5460

5561
map.file = "myfile.css"
5662
map.sourceRoot = "../dist"
5763
map.sources = [.init(url: "a.scss")]
5864
map.names = ["fred", "barney"]
59-
XCTAssertEqual(#"SourceMap(v=3 file="myfile.css" sourceRoot="../dist" #sources=1 #names=2 mappings="")"#, map.description)
65+
#expect(map.description == #"SourceMap(v=3 file="myfile.css" sourceRoot="../dist" #sources=1 #names=2 mappings="")"#)
6066

6167
try map.set(segments: [
6268
[
@@ -65,15 +71,16 @@ class TestBasics: XCTestCase {
6571
]
6672
])
6773
let segDesc = try UnpackedSourceMap(map).segmentsDescription
68-
XCTAssertEqual("""
69-
line=0 col=0-12 (source=0 line=0 col=0 name=1)
70-
col=13 (source=0 line=1 col=0 name=1)
71-
""", segDesc)
74+
#expect(segDesc == """
75+
line=0 col=0-12 (source=0 line=0 col=0 name=1)
76+
col=13 (source=0 line=1 col=0 name=1)
77+
""")
7278
_ = try map.encode() // to encode the mapping string
7379
print(map.description)
74-
XCTAssertTrue(map.description.hasSuffix(#" mappings="AAAAC,aACAA")"#))
80+
#expect(map.description.hasSuffix(#" mappings="AAAAC,aACAA")"#))
7581
}
7682

83+
@Test
7784
func testSourceURL() throws {
7885
var map = SourceMap()
7986
map.sources = [.init(url: "http://host/path/a.scss"),
@@ -82,13 +89,13 @@ class TestBasics: XCTestCase {
8289
let mapURL = URL(fileURLWithPath: "/web/main.map")
8390

8491
let source1 = map.getSourceURL(source: 0, sourceMapURL: mapURL)
85-
XCTAssertEqual("http://host/path/a.scss", source1.absoluteString)
92+
#expect(source1.absoluteString == "http://host/path/a.scss")
8693

8794
let source2 = map.getSourceURL(source: 1, sourceMapURL: mapURL)
88-
XCTAssertEqual("file:///dist/b.scss", source2.absoluteString)
95+
#expect(source2.absoluteString == "file:///dist/b.scss")
8996

9097
map.sourceRoot = "./../dist/"
9198
let source3 = map.getSourceURL(source: 2, sourceMapURL: mapURL)
92-
XCTAssertEqual("file:///dist/c.scss", source3.absoluteString)
99+
#expect(source3.absoluteString == "file:///dist/c.scss")
93100
}
94101
}

Tests/SourceMapperTests/TestHelpers.swift

-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99
import SourceMapper
10-
import XCTest
1110

1211
extension SourceMap {
1312
init(url: URL) throws {
@@ -22,25 +21,3 @@ extension SourceMap {
2221
try self.init(url: Self.fixturesURL.appendingPathComponent(fixtureName))
2322
}
2423
}
25-
26-
func XCTAssertThrows<T: Error>(_ errType: T.Type, _ callback: () throws -> Void) {
27-
do {
28-
try callback()
29-
} catch let error as T {
30-
print(error)
31-
} catch {
32-
XCTFail("Unexpected error: \(error)")
33-
}
34-
}
35-
36-
func XCTAssertSourceMapError(_ err: SourceMapError, _ callback: () throws -> Void) {
37-
do {
38-
try callback()
39-
XCTFail("Did not throw any errors")
40-
} catch let error as SourceMapError {
41-
XCTAssertEqual(err, error)
42-
print(error)
43-
} catch {
44-
XCTFail("Unexpected error: \(error)")
45-
}
46-
}

Tests/SourceMapperTests/TestJSON.swift

+23-13
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66
//
77

88
@testable import SourceMapper
9-
import XCTest
9+
import Testing
10+
11+
extension Tag {
12+
@Tag static var json: Self
13+
}
1014

1115
/// JSON code/decode logic and error handling
12-
class TestJSON: XCTestCase {
16+
@Suite(.tags(.json))
17+
final class TestJSON {
18+
@Test
1319
func testMissingFields() throws {
14-
XCTAssertThrows(Swift.DecodingError.self) {
20+
#expect(throws: Swift.DecodingError.self) {
1521
let map = try SourceMap("{}")
16-
XCTFail("Managed to decode bad map: \(map)")
22+
print("Bad map decoded: \(map)")
1723
}
1824
}
1925

26+
@Test
2027
func testBadVersion() throws {
2128
let badVersionJSON = """
2229
{
@@ -27,12 +34,13 @@ class TestJSON: XCTestCase {
2734
}
2835
"""
2936

30-
XCTAssertSourceMapError(.invalidFormat(4)) {
37+
#expect(throws: SourceMapError.invalidFormat(4)) {
3138
let map = try SourceMap(badVersionJSON)
32-
XCTFail("Managed to decode bad map: \(map)")
39+
print("Bad map decoded: \(map)")
3340
}
3441
}
3542

43+
@Test
3644
func testInconsistentSources() throws {
3745
let badSourcesJSON = """
3846
{
@@ -44,12 +52,13 @@ class TestJSON: XCTestCase {
4452
}
4553
"""
4654

47-
XCTAssertSourceMapError(.inconsistentSources(sourcesCount: 3, sourcesContentCount: 2)) {
55+
#expect(throws: SourceMapError.inconsistentSources(sourcesCount: 3, sourcesContentCount: 2)) {
4856
let map = try SourceMap(badSourcesJSON)
49-
XCTFail("Managed to decode bad map: \(map)")
57+
print("Bad map decoded: \(map)")
5058
}
5159
}
5260

61+
@Test
5362
func testSourceContent() throws {
5463
let sourcedJSON = """
5564
{
@@ -61,15 +70,16 @@ class TestJSON: XCTestCase {
6170
}
6271
"""
6372
let map = try SourceMap(sourcedJSON)
64-
XCTAssertEqual(2, map.sources.count)
65-
XCTAssertEqual("contents of a", map.sources[0].content)
66-
XCTAssertNil(map.sources[1].content)
73+
#expect(map.sources.count == 2)
74+
#expect("contents of a" == map.sources[0].content)
75+
#expect(map.sources[1].content == nil)
6776

6877
let encoded = try map.encode()
6978
let map2 = try SourceMap(encoded)
70-
XCTAssertEqual(map, map2)
79+
#expect(map == map2)
7180
}
7281

82+
@Test
7383
func testBadMapping() throws {
7484
let json = """
7585
{
@@ -79,7 +89,7 @@ class TestJSON: XCTestCase {
7989
"mappings": "AAA"
8090
}
8191
"""
82-
XCTAssertSourceMapError(.invalidVLQStringLength([0,0,0])) {
92+
#expect(throws: SourceMapError.invalidVLQStringLength([0,0,0])) {
8393
_ = try SourceMap(json).segments
8494
}
8595
}

0 commit comments

Comments
 (0)