@@ -131,6 +131,31 @@ func executeSwiftBuild(chdir: String, configuration: Configuration = .Debug, pri
131
131
}
132
132
}
133
133
134
+ //TODO: refactor swift-build and swift-test tools runing
135
+ func executeSwiftTest( dir: String , printIfError: Bool = false ) throws -> String {
136
+ let toolPath = Resources . findExecutable ( " swift-test " )
137
+ let env = [ String: String] ( )
138
+ let args = [ toolPath]
139
+
140
+ var out = " "
141
+ do {
142
+ // FIXME: this probably should be refactored to --chdir arg in swift-test
143
+ let cwd = try getcwd ( )
144
+ defer { _ = try ? POSIX . chdir ( cwd) }
145
+ try POSIX . chdir ( dir)
146
+
147
+ try popen ( args, redirectStandardError: true , environment: env) {
148
+ out += $0
149
+ }
150
+ return out
151
+ } catch {
152
+ if printIfError {
153
+ print ( out)
154
+ }
155
+ throw error
156
+ }
157
+ }
158
+
134
159
func mktmpdir( file: StaticString = #file, line: UInt = #line, @noescape body: ( String ) throws -> Void ) {
135
160
do {
136
161
try POSIX . mkdtemp ( " spm-tests " ) { dir in
@@ -169,6 +194,16 @@ func XCTAssertBuildFails(paths: String..., file: StaticString = #file, line: UIn
169
194
}
170
195
}
171
196
197
+ func XCTAssertTests( paths: String ... , file: StaticString = #file, line: UInt = #line) {
198
+ let prefix = Path . join ( paths)
199
+ do {
200
+ print ( " Testing " )
201
+ try executeSwiftTest ( prefix, printIfError: true )
202
+ } catch {
203
+ XCTFail ( " swift-test failed: \n \n \( error) \n " , file: file, line: line)
204
+ }
205
+ }
206
+
172
207
func XCTAssertFileExists( paths: String ... , file: StaticString = #file, line: UInt = #line) {
173
208
let path = Path . join ( paths)
174
209
if !path. isFile {
0 commit comments