@@ -131,6 +131,31 @@ func executeSwiftBuild(chdir: String, configuration: Configuration = .Debug, pri
131131 }
132132}
133133
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+
134159func mktmpdir( file: StaticString = #file, line: UInt = #line, @noescape body: ( String ) throws -> Void ) {
135160 do {
136161 try POSIX . mkdtemp ( " spm-tests " ) { dir in
@@ -169,6 +194,16 @@ func XCTAssertBuildFails(paths: String..., file: StaticString = #file, line: UIn
169194 }
170195}
171196
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+
172207func XCTAssertFileExists( paths: String ... , file: StaticString = #file, line: UInt = #line) {
173208 let path = Path . join ( paths)
174209 if !path. isFile {
0 commit comments