Commit 9e47f130 authored by Drew's avatar Drew

XCTest runner support on OSX

See #23
parent 457e4e99
......@@ -19,7 +19,8 @@ let tools: [String:Tool] = [
"shell": Shell(),
"atllbuild": ATllbuild(),
"nop": Nop(),
"noop": Nop()]
"xctestrun":XCTestRun()
]
/**
* A tool is a function that performs some operation, like building, or
......
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import atpkg
import Foundation
class XCTestRun : Tool {
func run(task: Task) {
guard let testExecutable = task["testExecutable"]?.string else {
fatalError("No testExecutable for XCTestRun")
}
#if os(OSX)
var workingDirectory = "/tmp/XXXXXXXXXXX"
var template = workingDirectory.cStringUsingEncoding(NSUTF8StringEncoding)!
workingDirectory = String(CString: mkdtemp(&template), encoding: NSUTF8StringEncoding)!
let manager = NSFileManager.defaultManager()
let executablePath = workingDirectory + "/XCTestRun.xctest/Contents/MacOS"
try! manager.createDirectoryAtPath(executablePath, withIntermediateDirectories: true, attributes: nil)
try! manager.copyItemAtPath(testExecutable, toPath: executablePath + "/XCTestRun")
var s = ""
s += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
s += "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
s += "<plist version=\"1.0\">\n"
s += "<dict>\n"
s += "<key>CFBundleDevelopmentRegion</key>\n"
s += "<string>en</string>\n"
s += "<key>CFBundleExecutable</key>\n"
s += "<string>XCTestRun</string>\n"
s += "<key>CFBundleIdentifier</key>\n"
s += "<string>org.swift.package-manager.dep-tests</string>\n"
s += "<key>CFBundleInfoDictionaryVersion</key>\n"
s += "<string>6.0</string>\n"
s += "<key>CFBundleName</key>\n"
s += "<string>NaOHTests</string>\n"
s += "<key>CFBundlePackageType</key>\n"
s += "<string>BNDL</string>\n"
s += "<key>CFBundleShortVersionString</key>\n"
s += "<string>1.0</string>\n"
s += "<key>CFBundleSignature</key>\n"
s += "<string>????</string>\n"
s += "<key>CFBundleSupportedPlatforms</key>\n"
s += "<array>\n"
s += "<string>MacOSX</string>\n"
s += "</array>\n"
s += "<key>CFBundleVersion</key>\n"
s += "<string>1</string>\n"
s += "</dict>\n"
s += "</plist>\n"
try! s.writeToFile(workingDirectory + "/XCTestRun.xctest/Contents/Info.plist", atomically: false, encoding: NSUTF8StringEncoding)
if system("xcrun xctest \(workingDirectory)/XCTestRun.xctest") != 0 {
fatalError("Test execution failed.")
}
#else
fatalError("Not implemented")
#endif
}
}
\ No newline at end of file
......@@ -181,6 +181,17 @@ final class ATllbuild : Tool {
linkOptions.append(os)
}
}
//xctestify
if task["xctestify"]?.bool == true {
precondition(outputType == .Executable, "You must use outputType: executable with xctestify.")
//inject platform-specific flags
#if os(OSX)
compileOptions.appendContentsOf(["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/"])
linkOptions.appendContentsOf(["-F", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-target", "x86_64-apple-macosx10.11", "-Xlinker", "-rpath", "-Xlinker", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/", "-Xlinker", "-bundle"])
#endif
}
guard let sourceDescriptions = task["source"]?.vector?.flatMap({$0.string}) else { fatalError("Can't find sources for atllbuild.") }
let sources = collectSources(sourceDescriptions, task: task)
......
(package
:name "xcs"
:tasks {
:build-lib {
:tool "atllbuild"
:source ["src/**.swift"]
:outputType "static-library"
:name "Foo"
:compileOptions ["-enable-testing"]
}
:build-tests {
:tool "atllbuild"
:source ["test/**.swift"]
:outputType "executable"
:name "footests"
:dependencies ["build-lib"]
:xctestify true
:linkWithProduct["Foo.a"]
}
:run-tests {
:tool "xctestrun"
:testExecutable ".atllbuild/products/footests"
}
}
)
\ No newline at end of file
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
class Foo {
func whatever() -> Int {
return 12
}
}
\ No newline at end of file
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@testable import Foo
import XCTest
class FooTests: XCTestCase {
var allTests : [(String, () -> Void)] {
return [
("testFoo", testFoo)
]
}
func testFoo() {
XCTAssert(Foo().whatever() == 12)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment