Skip to content

Commit dab7629

Browse files
authored
Merge pull request #40 from hartbit/update
Update TSC
2 parents b1fdbad + 45ac6b4 commit dab7629

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

Sources/TSCBasic/FileSystem.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,18 @@ extension FileSystem {
878878
}
879879
}
880880

881+
/// Write bytes to the path if the given contents are different.
882+
public func writeIfChanged(path: AbsolutePath, bytes: ByteString) throws {
883+
try createDirectory(path.parentDirectory, recursive: true)
884+
885+
// Return if the contents are same.
886+
if isFile(path), try readFileContents(path) == bytes {
887+
return
888+
}
889+
890+
try writeFileContents(path, bytes: bytes)
891+
}
892+
881893
/// Helper method to recurse and print the tree.
882894
private func recurse(fs: FileSystem, path: AbsolutePath, prefix: String = "") throws {
883895
let contents = try fs.getDirectoryContents(path)

Tests/LinuxMain.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
import XCTest
2-
3-
import TSCBasicTests
4-
import TSCTestSupportTests
5-
import TSCUtilityTests
6-
7-
var tests = [XCTestCaseEntry]()
8-
tests += TSCBasicTests.__allTests()
9-
tests += TSCTestSupportTests.__allTests()
10-
tests += TSCUtilityTests.__allTests()
11-
12-
XCTMain(tests)
1+
fatalError("Use `swift test --enable-test-discovery` to run tests")

Tests/TSCBasicPerformanceTests/ByteStringPerfTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import TSCTestSupport
1515

1616
class ByteStringPerfTests: XCTestCasePerf {
1717
func testInitialization() {
18+
#if os(macOS)
1819
let listOfStrings: [String] = (0..<10).map { "This is the number: \($0)!\n" }
1920
let expectedTotalCount = listOfStrings.map({ $0.utf8.count }).reduce(0, +)
2021
measure {
@@ -28,5 +29,6 @@ class ByteStringPerfTests: XCTestCasePerf {
2829
}
2930
XCTAssertEqual(count, expectedTotalCount * N)
3031
}
32+
#endif
3133
}
3234
}

Tests/TSCBasicPerformanceTests/OutputByteStreamPerfTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct ByteSequenceIterator: IteratorProtocol {
4545
class OutputByteStreamPerfTests: XCTestCasePerf {
4646

4747
func test1MBOfSequence_X10() {
48+
#if os(macOS)
4849
let sequence = ByteSequence()
4950
measure {
5051
for _ in 0..<10 {
@@ -55,9 +56,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
5556
XCTAssertEqual(stream.bytes.count, 1 << 20)
5657
}
5758
}
59+
#endif
5860
}
5961

6062
func test1MBOfByte_X10() {
63+
#if os(macOS)
6164
let byte = UInt8(0)
6265
measure {
6366
for _ in 0..<10 {
@@ -68,9 +71,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
6871
XCTAssertEqual(stream.bytes.count, 1 << 20)
6972
}
7073
}
74+
#endif
7175
}
7276

7377
func test1MBOfCharacters_X1() {
78+
#if os(macOS)
7479
measure {
7580
for _ in 0..<1 {
7681
let stream = BufferedOutputByteStream()
@@ -80,9 +85,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
8085
XCTAssertEqual(stream.bytes.count, 1 << 20)
8186
}
8287
}
88+
#endif
8389
}
8490

8591
func test1MBOf16ByteArrays_X100() {
92+
#if os(macOS)
8693
// Test writing 1MB worth of 16 byte strings.
8794
let bytes16 = [UInt8](repeating: 0, count: 1 << 4)
8895

@@ -95,10 +102,12 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
95102
XCTAssertEqual(stream.bytes.count, 1 << 20)
96103
}
97104
}
105+
#endif
98106
}
99107

100108
// This should give same performance as 16ByteArrays_X100.
101109
func test1MBOf16ByteArraySlice_X100() {
110+
#if os(macOS)
102111
let bytes32 = [UInt8](repeating: 0, count: 1 << 5)
103112
// Test writing 1MB worth of 16 byte strings.
104113
let bytes16 = bytes32.suffix(from: bytes32.count/2)
@@ -112,9 +121,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
112121
XCTAssertEqual(stream.bytes.count, 1 << 20)
113122
}
114123
}
124+
#endif
115125
}
116126

117127
func test1MBOf1KByteArrays_X1000() {
128+
#if os(macOS)
118129
// Test writing 1MB worth of 1K byte strings.
119130
let bytes1k = [UInt8](repeating: 0, count: 1 << 10)
120131

@@ -127,9 +138,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
127138
XCTAssertEqual(stream.bytes.count, 1 << 20)
128139
}
129140
}
141+
#endif
130142
}
131143

132144
func test1MBOf16ByteStrings_X10() {
145+
#if os(macOS)
133146
// Test writing 1MB worth of 16 byte strings.
134147
let string16 = String(repeating: "X", count: 1 << 4)
135148

@@ -142,9 +155,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
142155
XCTAssertEqual(stream.bytes.count, 1 << 20)
143156
}
144157
}
158+
#endif
145159
}
146160

147161
func test1MBOf1KByteStrings_X100() {
162+
#if os(macOS)
148163
// Test writing 1MB worth of 1K byte strings.
149164
let bytes1k = String(repeating: "X", count: 1 << 10)
150165

@@ -157,9 +172,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
157172
XCTAssertEqual(stream.bytes.count, 1 << 20)
158173
}
159174
}
175+
#endif
160176
}
161177

162178
func test1MBOfJSONEncoded16ByteStrings_X10() {
179+
#if os(macOS)
163180
// Test writing 1MB worth of JSON encoded 16 byte strings.
164181
let string16 = String(repeating: "X", count: 1 << 4)
165182

@@ -172,9 +189,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
172189
XCTAssertEqual(stream.bytes.count, 1 << 20)
173190
}
174191
}
192+
#endif
175193
}
176194

177195
func testFormattedJSONOutput() {
196+
#if os(macOS)
178197
// Test the writing of JSON formatted output using stream operators.
179198
struct Thing {
180199
var value: String
@@ -195,9 +214,11 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
195214
XCTAssertGreaterThan(stream.bytes.count, 1000)
196215
}
197216
}
217+
#endif
198218
}
199219

200220
func testJSONToString_X100() {
221+
#if os(macOS)
201222
let foo = JSON.dictionary([
202223
"foo": .string("bar"),
203224
"bar": .int(2),
@@ -221,5 +242,6 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
221242
XCTAssertGreaterThan(result.utf8.count, 10)
222243
}
223244
}
245+
#endif
224246
}
225247
}

Tests/TSCBasicPerformanceTests/PathPerfTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class PathPerfTests: XCTestCasePerf {
1717

1818
/// Tests creating very long AbsolutePaths by joining path components.
1919
func testJoinPerf_X100000() {
20+
#if os(macOS)
2021
let absPath = AbsolutePath("/hello/little")
2122
let relPath = RelativePath("world")
2223
let N = 100000
@@ -28,7 +29,6 @@ class PathPerfTests: XCTestCasePerf {
2829
}
2930
XCTAssertEqual(lengths, (absPath.pathString.utf8.count + 1 + relPath.pathString.utf8.count) &* N)
3031
}
32+
#endif
3133
}
32-
33-
// FIXME: We will obviously want a lot more tests here.
3434
}

Tests/TSCBasicPerformanceTests/SHA256PerfTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import TSCTestSupport
1515

1616
class SHA256PerfTests: XCTestCasePerf {
1717
func test20MBDigest_X1000() {
18+
#if os(macOS)
1819
let sha256 = SHA256()
1920
let byte = "f"
2021
let stream = BufferedOutputByteStream()
@@ -26,5 +27,6 @@ class SHA256PerfTests: XCTestCasePerf {
2627
XCTAssertEqual(sha256.hash(stream.bytes).hexadecimalRepresentation, "23d00697ba26b4140869bab958431251e7e41982794d41b605b6a1d5dee56abf")
2728
}
2829
}
30+
#endif
2931
}
3032
}

Tests/TSCBasicPerformanceTests/SortedArrayPerfTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import TSCTestSupport
1313

1414
class SortedArrayPerfTests: XCTestCasePerf {
1515
func testPerformanceOfSortedArrayInAscendingOrder() {
16+
#if os(macOS)
1617
measure() {
1718
var arr = SortedArray<Int>(areInIncreasingOrder: <)
1819
for i in 1...200_000 {
1920
arr.insert(i)
2021
}
2122
}
23+
#endif
2224
}
2325

2426
func testPerformanceOfSortedArrayInsertWithDuplicates() {
27+
#if os(macOS)
2528
let initial = SortedArray<Int>(0..<80_000, areInIncreasingOrder: <)
2629

2730
measure() {
@@ -30,18 +33,22 @@ class SortedArrayPerfTests: XCTestCasePerf {
3033
arr.insert(element)
3134
}
3235
}
36+
#endif
3337
}
3438

3539
func testPerformanceOfSortedArrayInsertContentsOfWithDuplicates() {
40+
#if os(macOS)
3641
let initial = SortedArray<Int>(0..<120_000, areInIncreasingOrder: <)
3742

3843
measure() {
3944
var arr = initial
4045
arr.insert(contentsOf: 60_000..<180_000)
4146
}
47+
#endif
4248
}
4349

4450
func testPerformanceOfSmallSortedArrayInsertContentsOfWithDuplicates() {
51+
#if os(macOS)
4552
let initial = SortedArray<Int>(0..<100, areInIncreasingOrder: <)
4653

4754
measure() {
@@ -50,5 +57,6 @@ class SortedArrayPerfTests: XCTestCasePerf {
5057
arr.insert(contentsOf: 50..<150)
5158
}
5259
}
60+
#endif
5361
}
5462
}

0 commit comments

Comments
 (0)