Skip to content

Commit 3314a6b

Browse files
authored
[test only] Improve filesIn test-helper function (#87)
1 parent d80a059 commit 3314a6b

10 files changed

+180
-282
lines changed
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -16,15 +16,12 @@ final class DocCConvertSynthesizedSymbolsTests: ConcurrencyRequiringTestCase {
1616
)
1717

1818
result.assertExitStatusEquals(0)
19-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
20-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
21-
XCTAssertEqual(
22-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
23-
[
24-
"documentation/packagewithconformancesymbols.json",
25-
"packagewithconformancesymbols/foo.json"
26-
]
27-
)
19+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
20+
21+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
22+
"documentation/packagewithconformancesymbols.json",
23+
"documentation/packagewithconformancesymbols/foo.json",
24+
])
2825
}
2926

3027
func testGenerateDocumentationWithSynthesizedSymbols() throws {
@@ -34,16 +31,13 @@ final class DocCConvertSynthesizedSymbolsTests: ConcurrencyRequiringTestCase {
3431
)
3532

3633
result.assertExitStatusEquals(0)
37-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
38-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
39-
XCTAssertEqual(
40-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
41-
[
42-
"documentation/packagewithconformancesymbols.json",
43-
"packagewithconformancesymbols/foo.json",
44-
"foo/equatable-implementations.json",
45-
"foo/!=(_:_:).json"
46-
]
47-
)
34+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
35+
36+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
37+
"documentation/packagewithconformancesymbols.json",
38+
"documentation/packagewithconformancesymbols/foo.json",
39+
"documentation/packagewithconformancesymbols/foo/!=(_:_:).json",
40+
"documentation/packagewithconformancesymbols/foo/equatable-implementations.json",
41+
])
4842
}
4943
}
Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -16,22 +16,9 @@ final class MixedTargetsTests: ConcurrencyRequiringTestCase {
1616
)
1717

1818
result.assertExitStatusEquals(0)
19-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
19+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
2020

21-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
22-
23-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
24-
25-
XCTAssertEqual(
26-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
27-
[
28-
"documentation/executable.json",
29-
"executable/foo.json",
30-
"foo/foo().json",
31-
"foo/main().json",
32-
"foo/init().json",
33-
]
34-
)
21+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), expectedExecutableDataFiles)
3522
}
3623

3724
func testGenerateDocumentationForMultipleSpecificTargets() throws {
@@ -41,42 +28,31 @@ final class MixedTargetsTests: ConcurrencyRequiringTestCase {
4128
)
4229

4330
result.assertExitStatusEquals(0)
31+
let outputArchives = result.referencedDocCArchives
4432
XCTAssertEqual(result.referencedDocCArchives.count, 2)
4533

46-
let executableDoccArchiveURL = try XCTUnwrap(
47-
result.referencedDocCArchives.first { archive in
48-
archive.lastPathComponent.contains("Executable")
49-
}
50-
)
51-
52-
let libraryDoccArchiveURL = try XCTUnwrap(
53-
result.referencedDocCArchives.first { archive in
54-
archive.lastPathComponent.contains("Library")
55-
}
56-
)
57-
58-
let executableDataDirectoryContents = try filesIn(.dataSubdirectory, of: executableDoccArchiveURL)
59-
60-
XCTAssertEqual(
61-
Set(executableDataDirectoryContents.map(\.lastTwoPathComponents)),
62-
[
63-
"documentation/executable.json",
64-
"executable/foo.json",
65-
"foo/foo().json",
66-
"foo/main().json",
67-
"foo/init().json",
68-
]
34+
let executableArchiveURL = try XCTUnwrap(
35+
outputArchives.first(where: { $0.lastPathComponent == "Executable.doccarchive" })
6936
)
70-
71-
let libraryDataDirectoryContents = try filesIn(.dataSubdirectory, of: libraryDoccArchiveURL)
72-
73-
XCTAssertEqual(
74-
Set(libraryDataDirectoryContents.map(\.lastTwoPathComponents)),
75-
[
76-
"documentation/library.json",
77-
"library/foo.json",
78-
"foo/foo().json",
79-
]
37+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: executableArchiveURL), expectedExecutableDataFiles)
38+
39+
let libraryArchiveURL = try XCTUnwrap(
40+
outputArchives.first(where: { $0.lastPathComponent == "Library.doccarchive" })
8041
)
42+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: libraryArchiveURL), expectedLibraryDataFiles)
8143
}
8244
}
45+
46+
private let expectedExecutableDataFiles = [
47+
"documentation/executable.json",
48+
"documentation/executable/foo.json",
49+
"documentation/executable/foo/foo().json",
50+
"documentation/executable/foo/init().json",
51+
"documentation/executable/foo/main().json",
52+
]
53+
54+
private let expectedLibraryDataFiles = [
55+
"documentation/library.json",
56+
"documentation/library/foo.json",
57+
"documentation/library/foo/foo().json",
58+
]
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -16,21 +16,14 @@ final class SingleExecutableTargetTests: ConcurrencyRequiringTestCase {
1616
)
1717

1818
result.assertExitStatusEquals(0)
19-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
19+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
2020

21-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
22-
23-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
24-
25-
XCTAssertEqual(
26-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
27-
[
28-
"documentation/executable.json",
29-
"executable/foo.json",
30-
"foo/foo().json",
31-
"foo/main().json",
32-
"foo/init().json",
33-
]
34-
)
21+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
22+
"documentation/executable.json",
23+
"documentation/executable/foo.json",
24+
"documentation/executable/foo/foo().json",
25+
"documentation/executable/foo/init().json",
26+
"documentation/executable/foo/main().json",
27+
])
3528
}
3629
}
Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -16,42 +16,13 @@ final class SingleLibraryTargetTests: ConcurrencyRequiringTestCase {
1616
)
1717

1818
result.assertExitStatusEquals(0)
19-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
19+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
2020

21-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
22-
23-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
24-
25-
XCTAssertEqual(
26-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
27-
[
28-
"documentation/library.json",
29-
"library/foo.json",
30-
"foo/foo().json",
31-
]
32-
)
33-
}
34-
35-
func testDocumentationGenerationDoesNotEmitErrors() throws {
36-
let result = try swiftPackage(
37-
"generate-documentation",
38-
workingDirectory: try setupTemporaryDirectoryForFixture(named: "SingleLibraryTarget")
39-
)
40-
41-
result.assertExitStatusEquals(0)
42-
43-
/*
44-
45-
Skipping the remaining assertion because SwiftPM has recently started emitting regular
46-
build status logging to standard error instead of standard output.
47-
48-
Tracked with rdar://89598464.
49-
50-
XCTAssertTrue(
51-
result.standardError.isEmpty,
52-
"Standard error should be empty. Contains: '\(result.standardError)'."
53-
)
54-
*/
21+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
22+
"documentation/library.json",
23+
"documentation/library/foo.json",
24+
"documentation/library/foo/foo().json",
25+
])
5526
}
5627

5728
func testGenerateDocumentationWithCustomOutput() throws {
@@ -66,12 +37,12 @@ final class SingleLibraryTargetTests: ConcurrencyRequiringTestCase {
6637
)
6738

6839
result.assertExitStatusEquals(0)
69-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
70-
let referencedDoccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
71-
72-
XCTAssertEqual(referencedDoccArchiveURL.path, customOutputDirectory.path)
40+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
7341

74-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: referencedDoccArchiveURL)
75-
XCTAssertEqual(dataDirectoryContents.count, 3)
42+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
43+
"documentation/library.json",
44+
"documentation/library/foo.json",
45+
"documentation/library/foo/foo().json",
46+
])
7647
}
7748
}

IntegrationTests/Tests/SnippetDocumentationGenerationTests.swift

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -18,47 +18,29 @@ final class SnippetDocumentationGenerationTests: ConcurrencyRequiringTestCase {
1818
)
1919

2020
result.assertExitStatusEquals(0)
21-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
22-
23-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
24-
25-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
26-
27-
XCTAssertEqual(
28-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
29-
[
30-
"documentation/library.json",
31-
"library/beststruct.json",
32-
"beststruct/init().json",
33-
"beststruct/best().json",
34-
]
35-
)
36-
37-
let subDirectoriesOfSymbolGraphDirectory = try FileManager.default.contentsOfDirectory(
21+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
22+
23+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
24+
"documentation/library.json",
25+
"documentation/library/beststruct.json",
26+
"documentation/library/beststruct/best().json",
27+
"documentation/library/beststruct/init().json",
28+
])
29+
30+
let symbolGraphSubDirectories = try FileManager.default.contentsOfDirectory(
3831
at: result.symbolGraphsDirectory,
3932
includingPropertiesForKeys: nil
4033
)
41-
42-
XCTAssertEqual(
43-
Set(subDirectoriesOfSymbolGraphDirectory.map(\.lastTwoPathComponents)),
44-
[
45-
"symbol-graphs/snippet-symbol-graphs",
46-
"symbol-graphs/unified-symbol-graphs",
47-
]
48-
)
49-
50-
let unifiedSymbolGraphDirectory = subDirectoriesOfSymbolGraphDirectory.first {
51-
$0.pathComponents.last == "unified-symbol-graphs"
52-
}!
53-
54-
let symbolGraphEnumerator = FileManager.default.enumerator(at: unifiedSymbolGraphDirectory,
55-
includingPropertiesForKeys: [.isRegularFileKey])!
56-
let symbolGraphPaths = try (symbolGraphEnumerator.allObjects as! [URL]).filter {
57-
try $0.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile!
58-
}
59-
XCTAssertNotNil(symbolGraphPaths.first {
60-
$0.pathComponents.last == "\(packageName)-snippets.symbols.json"
61-
})
34+
XCTAssertEqual(symbolGraphSubDirectories.map(\.lastPathComponent).sorted(), [
35+
"snippet-symbol-graphs",
36+
"unified-symbol-graphs",
37+
])
38+
39+
let unifiedSymbolGraphDirectory = try XCTUnwrap(symbolGraphSubDirectories.last)
40+
let symbolGraphFileNames = try filesIn(unifiedSymbolGraphDirectory).map(\.lastPathComponent)
41+
XCTAssert(symbolGraphFileNames.contains([
42+
"\(packageName)-snippets.symbols.json"
43+
]))
6244
}
6345

6446
func testPreviewDocumentationWithSnippets() throws {
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
66
// See https://swift.org/LICENSE.txt for license information
@@ -16,21 +16,14 @@ final class TargetWithDocCCatalogTests: ConcurrencyRequiringTestCase {
1616
)
1717

1818
result.assertExitStatusEquals(0)
19-
XCTAssertEqual(result.referencedDocCArchives.count, 1)
19+
let archiveURL = try XCTUnwrap(result.onlyOutputArchive)
2020

21-
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
22-
23-
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
24-
25-
XCTAssertEqual(
26-
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
27-
[
28-
"documentation/librarywithdocccatalog.json",
29-
"librarywithdocccatalog/article-one.json",
30-
"librarywithdocccatalog/article-two.json",
31-
"librarywithdocccatalog/foo.json",
32-
"foo/foo().json",
33-
]
34-
)
21+
XCTAssertEqual(try relativeFilePathsIn(.dataSubdirectory, of: archiveURL), [
22+
"documentation/librarywithdocccatalog.json",
23+
"documentation/librarywithdocccatalog/article-one.json",
24+
"documentation/librarywithdocccatalog/article-two.json",
25+
"documentation/librarywithdocccatalog/foo.json",
26+
"documentation/librarywithdocccatalog/foo/foo().json",
27+
])
3528
}
3629
}

0 commit comments

Comments
 (0)