@@ -20,26 +20,31 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
20
20
withExtension: " docc " ,
21
21
subdirectory: " Test Bundles "
22
22
) !
23
-
23
+
24
24
private let testTemplateURL = Bundle . module. url (
25
25
forResource: " Test Template " ,
26
26
withExtension: nil ,
27
27
subdirectory: " Test Resources "
28
28
) !
29
-
29
+
30
30
func testSourceRepositoryAllArgumentsSpecified( ) throws {
31
+ let checkoutPath = " checkout path "
32
+ var absoluteCheckoutPath = URL ( fileURLWithPath: checkoutPath) . absoluteString
33
+ let startIndex = absoluteCheckoutPath. index ( absoluteCheckoutPath. startIndex, offsetBy: 7 )
34
+ absoluteCheckoutPath = String ( absoluteCheckoutPath [ startIndex... ] )
35
+
31
36
for sourceService in [ " github " , " gitlab " , " bitbucket " ] {
32
37
try assertSourceRepositoryArguments (
33
- checkoutPath: " checkout path " ,
38
+ checkoutPath: checkoutPath ,
34
39
sourceService: sourceService,
35
40
sourceServiceBaseURL: " https://example.com/path/to/base "
36
41
) { action in
37
- XCTAssertEqual ( action. sourceRepository? . checkoutPath, " checkout path " )
42
+ XCTAssertEqual ( action. sourceRepository? . checkoutPath, absoluteCheckoutPath )
38
43
XCTAssertEqual ( action. sourceRepository? . sourceServiceBaseURL. absoluteString, " https://example.com/path/to/base " )
39
44
}
40
45
}
41
46
}
42
-
47
+
43
48
func testDoesNotSetSourceRepositoryIfBothCheckoutPathAndsourceServiceBaseURLArgumentsAreMissing( ) throws {
44
49
try assertSourceRepositoryArguments (
45
50
checkoutPath: nil ,
@@ -49,7 +54,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
49
54
XCTAssertNil ( action. sourceRepository)
50
55
}
51
56
}
52
-
57
+
53
58
func testThrowsValidationErrorWhenSourceServiceIsSpecifiedButNotSourceServiceBaseURL( ) throws {
54
59
XCTAssertThrowsError (
55
60
try assertSourceRepositoryArguments (
@@ -67,7 +72,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
67
72
)
68
73
}
69
74
}
70
-
75
+
71
76
func testThrowsValidationErrorWhenSourceServiceBaseURLIsSpecifiedButNotSourceService( ) throws {
72
77
XCTAssertThrowsError (
73
78
try assertSourceRepositoryArguments (
@@ -85,7 +90,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
85
90
)
86
91
}
87
92
}
88
-
93
+
89
94
func testThrowsValidationErrorWhenSourceServiceBaseURLIsInvalid( ) throws {
90
95
XCTAssertThrowsError (
91
96
try assertSourceRepositoryArguments (
@@ -100,7 +105,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
100
105
)
101
106
}
102
107
}
103
-
108
+
104
109
func testThrowsValidationErrorWhenCheckoutPathIsNotSpecified( ) throws {
105
110
XCTAssertThrowsError (
106
111
try assertSourceRepositoryArguments (
@@ -118,7 +123,7 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
118
123
)
119
124
}
120
125
}
121
-
126
+
122
127
func testThrowsValidationErrorWhenSourceServiceIsInvalid( ) throws {
123
128
XCTAssertThrowsError (
124
129
try assertSourceRepositoryArguments (
@@ -133,15 +138,15 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
133
138
)
134
139
}
135
140
}
136
-
141
+
137
142
private func assertSourceRepositoryArguments(
138
143
checkoutPath: String ? ,
139
144
sourceService: String ? ,
140
145
sourceServiceBaseURL: String ? ,
141
146
assertion: ( ( ConvertAction ) throws -> Void ) ? = nil
142
147
) throws {
143
148
SetEnvironmentVariable ( TemplateOption . environmentVariableKey, testTemplateURL. path)
144
-
149
+
145
150
var arguments : [ String ] = [ testBundleURL. path]
146
151
if let checkoutPath {
147
152
arguments. append ( contentsOf: [ " --checkout-path " , checkoutPath] )
@@ -152,9 +157,9 @@ class ConvertSubcommandSourceRepositoryTests: XCTestCase {
152
157
if let sourceServiceBaseURL {
153
158
arguments. append ( contentsOf: [ " --source-service-base-url " , sourceServiceBaseURL] )
154
159
}
155
-
160
+
156
161
let convertOptions = try Docc . Convert. parse ( arguments)
157
-
162
+
158
163
let result = try ConvertAction ( fromConvertCommand: convertOptions)
159
164
try assertion ? ( result)
160
165
}
0 commit comments