forked from danger/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDangerFileGeneratorTests.swift
130 lines (101 loc) · 3.94 KB
/
DangerFileGeneratorTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import Foundation
import Logger
@testable import RunnerLib
import SnapshotTesting
import XCTest
final class DangerFileGeneratorTests: XCTestCase {
private var logger: Logger {
Logger(isVerbose: false, isSilent: false, printer: SpyPrinter())
}
private var createdFiles: [String]!
private var generator: DangerFileGenerator!
private var generatedFilePath: String {
"GeneratedTestDangerfile.swift"
}
private var file1Path: String {
"GeneratedTestFile1.swift"
}
private var file2Path: String {
"GeneratedTestFile2.swift"
}
private var file3Path: String {
"GeneratedTestFile3.swift"
}
override func setUp() {
super.setUp()
createdFiles = [generatedFilePath]
generator = DangerFileGenerator()
// record = false
}
override func tearDown() {
createdFiles.forEach { try? FileManager.default.removeItem(atPath: $0) }
createdFiles = nil
generator = nil
super.tearDown()
}
func testItGeneratesTheCorrectFileWhenThereAreNoImports() throws {
try generator.generateDangerFile(fromContent: contentWithoutImports, fileName: generatedFilePath, logger: logger)
assertSnapshot(matching: try generatedContent(), as: .lines)
}
func testItGeneratesTheCorrectFileWhenThereIsASingleImport() throws {
try? file1Content.write(toFile: file1Path, atomically: true, encoding: .utf8)
createdFiles.append(file1Path)
try generator.generateDangerFile(fromContent: contentWithOneImport, fileName: generatedFilePath, logger: logger)
assertSnapshot(matching: try generatedContent(), as: .lines)
}
func testItGeneratesTheCorrectFileWhenThereIsAreMultipleImports() throws {
try? file1Content.write(toFile: file1Path, atomically: true, encoding: .utf8)
try? file2Content.write(toFile: file2Path, atomically: true, encoding: .utf8)
try? file3Content.write(toFile: file3Path, atomically: true, encoding: .utf8)
createdFiles.append(file1Path)
createdFiles.append(file2Path)
createdFiles.append(file3Path)
try generator.generateDangerFile(fromContent: contentWithMultipleImports, fileName: generatedFilePath, logger: logger)
assertSnapshot(matching: try generatedContent(), as: .lines)
}
func testItGeneratesTheCorrectFileWhenOneOfTheImportedFilesIsMissing() throws {
try? file1Content.write(toFile: file1Path, atomically: true, encoding: .utf8)
try? file2Content.write(toFile: file2Path, atomically: true, encoding: .utf8)
createdFiles.append(file1Path)
createdFiles.append(file2Path)
try generator.generateDangerFile(fromContent: contentWithMultipleImports, fileName: generatedFilePath, logger: logger)
assertSnapshot(matching: try generatedContent(), as: .lines)
}
}
extension DangerFileGeneratorTests {
private var contentWithoutImports: String {
"""
message("Text")
message("Another Text")
"""
}
private var contentWithOneImport: String {
"// fileImport: " + file1Path + "\n" + contentWithoutImports
}
private var contentWithMultipleImports: String {
"// fileImport: " + file2Path + "\n\n" +
"// fileImport: " + file3Path + "\n" + contentWithOneImport
}
private var file1Content: String {
"""
file1Content 👍🏻
secondLine
"""
}
private var file2Content: String {
"""
file2Content ⚠️
"""
}
private var file3Content: String {
"""
file3Content 👩👩👦👦
secondLine
really really really really really really really really really really really really \
really really really really really really really really really really long text
"""
}
private func generatedContent() throws -> String {
try String(contentsOfFile: generatedFilePath)
}
}