0001 // 0002 // ModuleTests.swift 0003 // SourceKitten 0004 // 0005 // Created by JP Simard on 2015-01-07. 0006 // Copyright (c) 2015 SourceKitten. All rights reserved. 0007 // 0008 0009 import Foundation 0010 import SourceKittenFramework 0011 import XCTest 0012 0013 class ModuleTests: XCTestCase { 0014 0015 // protocol XCTestCaseProvider 0016 lazy var allTests: [(String, () throws -> Void)] = [ 0017 ("testModuleNilInPathWithNoXcodeProject", self.testModuleNilInPathWithNoXcodeProject), 0018 // ("testSourceKittenFrameworkDocsAreValidJSON", 0019 // self.testSourceKittenFrameworkDocsAreValidJSON), FIXME: Failing on SPM 0020 // ("testCommandantDocs", self.testCommandantDocs), FIXME: Failing on SPM 0021 ] 0022 0023 func testModuleNilInPathWithNoXcodeProject
main_.swift:15 ModuleTests(),() { 0024 let pathWithNoXcodeProject = (__FILE__ as NSString).stringByDeletingLastPathComponent 0025 let model = Module(xcodeBuildArguments: [], name: nil, inPath: pathWithNoXcodeProject) 0026 XCTAssert(model == nil, "model initialization without any Xcode project should fail") 0027 } 0028 0029 func testSourceKittenFrameworkDocsAreValidJSON() { 0030 let projectRoot = (((__FILE__ as NSString) 0031 .stringByDeletingLastPathComponent as NSString) 0032 .stringByDeletingLastPathComponent as NSString) 0033 .stringByDeletingLastPathComponent 0034 let sourceKittenModule = Module(xcodeBuildArguments: ["-workspace", "SourceKitten.xcworkspace", "-scheme", "SourceKittenFramework"], name: nil, inPath: projectRoot)! 0035 let docsJSON = sourceKittenModule.docs.description 0036 XCTAssert(docsJSON.rangeOfString("error type") == nil) 0037 do { 0038 let jsonArray = try NSJSONSerialization.JSONObjectWithData(docsJSON.dataUsingEncoding(NSUTF8StringEncoding)!, options: []) as? NSArray 0039 XCTAssertNotNil(jsonArray, "JSON should be propery parsed") 0040 } catch { 0041 XCTFail("JSON should be propery parsed") 0042 } 0043 } 0044 0045 func testCommandantDocs() { 0046 let projectRoot = (((__FILE__ as NSString) 0047 .stringByDeletingLastPathComponent as NSString) 0048 .stringByDeletingLastPathComponent as NSString) 0049 .stringByDeletingLastPathComponent 0050 let commandantPath = projectRoot + "/Carthage/Checkouts/Commandant/" 0051 let commandantModule = Module(xcodeBuildArguments: ["-workspace", "Commandant.xcworkspace", "-scheme", "Commandant"], name: nil, inPath: commandantPath)! 0052 let escapedCommandantPath = commandantPath.stringByReplacingOccurrencesOfString("/", withString: "\\/") 0053 let comparisonString = commandantModule.docs.description.stringByReplacingOccurrencesOfString(escapedCommandantPath, withString: "") 0054 let expected = File(path: fixturesDirectory + "Commandant.json")!.contents 0055 let actualDocsObject = try! NSJSONSerialization.JSONObjectWithData(comparisonString.dataUsingEncoding(NSUTF8StringEncoding)!, options: []) as! NSArray 0056 let expectedDocsObject = try! NSJSONSerialization.JSONObjectWithData(expected.dataUsingEncoding(NSUTF8StringEncoding)!, options: []) as! NSArray 0057 XCTAssertEqual(actualDocsObject, expectedDocsObject, "should generate expected docs for Swift module") 0058 } 0059 } 0060
ModuleTests.swift:17 ("testModuleNilInPathWithNoXcodeProject", self.testModuleNilInPathWithNoXcodeProject),