Skip to content

Commit 172a0aa

Browse files
SDGGiesbrechtaciidgh
authored andcommitted
Unicode‐Heavy Test Fixture (#2356)
* Added Unicode‐heavy fixture. * Refreshed test manifest. * Added consecutive regional indicator. * Exempted Linux for now.
1 parent e34bdb2 commit 172a0aa

File tree

15 files changed

+180
-0
lines changed

15 files changed

+180
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
import Foundation
5+
6+
/// This string demonstrates as many complications of Unicode as possible.
7+
let complicatedString = "πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄"
8+
// π U+03C0: A simple BMP scalar.
9+
//‎ שּׁ U+FB2C: Changes under both NFC and NFD.
10+
// µ U+00B5: Changes under NFKC and NFKD.
11+
// 𝄞 U+1D11E: Simple non‐BMP scalar.
12+
// 🇺🇳 U+1F1FA U+1F1F3: Multi‐scalar character.
13+
// 🇮🇱 U+1F1EE U+1F1F1: Second consecutive regional indicator. (Complicated grapheme breaking.)
14+
// x̱̱̱̱̱̄̄̄̄̄ U+0078 (U+0331 U+0304) × 5: Extremely long combining sequence. (Also reordrant under normalization.)
15+
16+
// The following verifies that sources haven’t been normalized, which would reduce the test’s effectiveness.
17+
var verify = "\u{03C0}\u{0FB2C}\u{00B5}\u{1D11E}\u{1F1FA}\u{1F1F3}\u{1F1EE}\u{1F1F1}\u{0078}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}"
18+
assert(
19+
complicatedString.unicodeScalars.elementsEqual(verify.unicodeScalars),
20+
"\(complicatedString)\(verify)")
21+
22+
let package = Package(
23+
name: complicatedString,
24+
products: [
25+
.library(
26+
name: complicatedString,
27+
targets: [complicatedString]),
28+
.executable(name: complicatedString + "‐tool", targets: [complicatedString + "‐tool"])
29+
],
30+
dependencies: [
31+
.package(url: "../UnicodeDependency‐\(complicatedString)", from: "1.0.0")
32+
],
33+
targets: [
34+
.target(
35+
name: complicatedString,
36+
dependencies: [.product(name: "UnicodeDependency‐\(complicatedString)")]),
37+
.target(
38+
name: complicatedString + "‐tool",
39+
dependencies: [.target(name: complicatedString)]),
40+
.testTarget(
41+
name: complicatedString + "Tests",
42+
dependencies: [.target(name: complicatedString)]),
43+
]
44+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Unicode
2+
3+
This fixture makes extensive use of exotic Unicode. While deliberately trying to break a as many common false assumptions as possible, *this is a valid package*, and clients are encouraged to test their functionality with it. A tool that successfully handles this package is unlikely to encounter problems with any real‐world package in any human language.
4+
5+
The neighbouring package `UnicodeDependency‐πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄` must be placed next this package and tagged with version 1.0.0. (This is necessary to use Unicode in dependency URLs in this package’s manifest.)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public struct πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄ {
2+
public init() {}
3+
public var πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄ = "Hello, World!"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import π_µ_____x__________
2+
3+
print(πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄().πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import XCTest
2+
3+
import π_µ_____x__________Tests
4+
5+
var tests = [XCTestCaseEntry]()
6+
tests += π_µ_____x__________Tests.__allTests()
7+
8+
XCTMain(tests)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if !canImport(ObjectiveC)
2+
import XCTest
3+
4+
extension πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄Tests {
5+
// DO NOT MODIFY: This is autogenerated, use:
6+
// `swift test --generate-linuxmain`
7+
// to regenerate.
8+
static let __allTests__πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄Tests = [
9+
("testπשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄", testπשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄),
10+
]
11+
}
12+
13+
public func __allTests() -> [XCTestCaseEntry] {
14+
return [
15+
testCase(πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄Tests.__allTests__πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄Tests),
16+
]
17+
}
18+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import XCTest
2+
3+
// TODO: - Can imports be made less ugly? (SR‐10839)
4+
//@testable import πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄
5+
@testable import π_µ_____x__________
6+
// (These characters all work for identifiers. See below.)
7+
8+
final class πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄Tests: XCTestCase {
9+
10+
func testπשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄() {
11+
XCTAssertEqual(πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄().πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄, "Hello, World!")
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SomeOtherPackage",
7+
dependencies: [
8+
.package(path: "../../"),
9+
],
10+
targets: [
11+
.target(
12+
name: "SomeOtherPackage",
13+
dependencies: ["πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄"]),
14+
]
15+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SomeOtherPackage
2+
3+
This nested utility package refers back to the main repository as a local dependency.
4+
5+
If client tools accidently pick this package up as part of the main repository package, dependency resolution could become circular or otherwise problematic.
6+
7+
(Prior to direct Xcode support for packages, this repository structure was a common way of hiding executable utilities from `generate-xcodeproj`, so that the main package would still be viable for iOS.)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, world!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "UnicodeDependency‐πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄",
7+
products: [
8+
.library(
9+
name: "UnicodeDependency‐πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄",
10+
targets: ["UnicodeDependency‐πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄"]),
11+
],
12+
targets: [
13+
.target(
14+
name: "UnicodeDependency‐πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄",
15+
dependencies: []),
16+
]
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# UnicodeDependency‐πשּׁµ𝄞🇺🇳x̱̱̱̱̱̄̄̄̄̄
2+
3+
A description of this package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct UnicodeDependency_UnicodeDependency_πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄ {
2+
var text = "Hello, World!"
3+
}

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import TSCUtility
1616
import TSCLibc
1717
import class Foundation.ProcessInfo
1818
import class Foundation.Thread
19+
import SourceControl
20+
import SPMTestSupport
1921
import Workspace
2022

2123
typealias ProcessID = TSCBasic.Process.ProcessID
@@ -435,4 +437,40 @@ class MiscellaneousTestCase: XCTestCase {
435437
}
436438
#endif
437439
}
440+
441+
func testUnicode() {
442+
#if !os(Linux) // TODO: - Linux has trouble with this and needs investigation.
443+
fixture(name: "Miscellaneous/Unicode") { prefix in
444+
// See the fixture manifest for an explanation of this string.
445+
let complicatedString = "πשּׁµ𝄞🇺🇳🇮🇱x̱̱̱̱̱̄̄̄̄̄"
446+
let verify = "\u{03C0}\u{0FB2C}\u{00B5}\u{1D11E}\u{1F1FA}\u{1F1F3}\u{1F1EE}\u{1F1F1}\u{0078}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}\u{0331}\u{0304}"
447+
XCTAssert(
448+
complicatedString.unicodeScalars.elementsEqual(verify.unicodeScalars),
449+
"\(complicatedString)\(verify)")
450+
451+
// ••••• Set up dependency.
452+
let dependencyName = "UnicodeDependency‐\(complicatedString)"
453+
let dependencyOrigin = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory
454+
.appending(component: "Fixtures")
455+
.appending(component: "Miscellaneous")
456+
.appending(component: dependencyName)
457+
let dependencyDestination = prefix.parentDirectory.appending(component: dependencyName)
458+
try? FileManager.default.removeItem(atPath: dependencyDestination.pathString)
459+
defer { try? FileManager.default.removeItem(atPath: dependencyDestination.pathString) }
460+
try FileManager.default.copyItem(
461+
atPath: dependencyOrigin.pathString,
462+
toPath: dependencyDestination.pathString)
463+
let dependency = GitRepository(path: dependencyDestination)
464+
try dependency.create()
465+
try dependency.stageEverything()
466+
try dependency.commit()
467+
try dependency.tag(name: "1.0.0")
468+
// •••••
469+
470+
// Attempt several operations.
471+
try SwiftPMProduct.SwiftTest.execute([], packagePath: prefix)
472+
try SwiftPMProduct.SwiftRun.execute([complicatedString + "‐tool"], packagePath: prefix)
473+
}
474+
#endif
475+
}
438476
}

Tests/FunctionalTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extension MiscellaneousTestCase {
5050
("testSwiftTestFilter", testSwiftTestFilter),
5151
("testSwiftTestLinuxMainGeneration", testSwiftTestLinuxMainGeneration),
5252
("testSwiftTestParallel", testSwiftTestParallel),
53+
("testUnicode", testUnicode),
5354
]
5455
}
5556

0 commit comments

Comments
 (0)