<commit_before>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import func POSIX.mkdtemp
import PackageType
import Xcodeproj
import Utility
import XCTest


// copy pasta
func mktmpdir(_ file: StaticString = #file, line: UInt = #line, body: @noescape(String) throws -> Void) {
    do {
        try POSIX.mkdtemp("spm-tests") { dir in
            defer { _ = try? rmtree(dir) }
            try body(dir)
        }
    } catch {
        XCTFail("\(error)", file: file, line: line)
    }
}

func XCTAssertDirectoryExists(_ paths: String..., file: StaticString = #file, line: UInt = #line) {
    let path = Path.join(paths)
    if !path.isDirectory {
        XCTFail("Expected directory doesn’t exist: \(path)", file: file, line: line)
    }
}


#if os(OSX)
class TestGeneration: XCTestCase {

    /// --> this comment is here <--

    func testXcodeBuildCanParseIt() {
        mktmpdir { dstdir in
            func dummy() throws -> [XcodeModuleProtocol] {
                return [try SwiftModule(name: "DummyModuleName", sources: Sources(paths: [], root: dstdir))]
            }

            let projectName = "DummyProjectName"
            let srcroot = dstdir
            let modules = try dummy()
            let products: [Product] = []

            struct Options: XcodeprojOptions {
                let Xcc = [String]()
                let Xld = [String]()
                let Xswiftc = [String]()
                let xcconfigOverrides: String? = nil
            }
            let outpath = try Xcodeproj.generate(dstdir: dstdir, projectName: projectName, srcroot: srcroot, modules: modules, externalModules: [], products: products, options: Options())

            XCTAssertDirectoryExists(outpath)
            XCTAssertEqual(outpath, Path.join(dstdir, "\(projectName).xcodeproj"))

            let output = try popen(["xcodebuild", "-list", "-project", outpath])

            let expectedOutput = "Information about project \"DummyProjectName\":\n    Targets:\n        DummyModuleName\n\n    Build Configurations:\n        Debug\n        Release\n\n    If no build configuration is specified and -scheme is not passed then \"Debug\" is used.\n\n    Schemes:\n        DummyProjectName\n"

            XCTAssertEqual(output, expectedOutput)
        }
    }
}
#endif<commit_msg>[tests] Protect a test against TOOLCHAINS being set.<commit_after>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import func POSIX.mkdtemp
import PackageType
import Xcodeproj
import Utility
import XCTest


// copy pasta
func mktmpdir(_ file: StaticString = #file, line: UInt = #line, body: @noescape(String) throws -> Void) {
    do {
        try POSIX.mkdtemp("spm-tests") { dir in
            defer { _ = try? rmtree(dir) }
            try body(dir)
        }
    } catch {
        XCTFail("\(error)", file: file, line: line)
    }
}

func XCTAssertDirectoryExists(_ paths: String..., file: StaticString = #file, line: UInt = #line) {
    let path = Path.join(paths)
    if !path.isDirectory {
        XCTFail("Expected directory doesn’t exist: \(path)", file: file, line: line)
    }
}


#if os(OSX)
class TestGeneration: XCTestCase {

    /// --> this comment is here <--

    func testXcodeBuildCanParseIt() {
        mktmpdir { dstdir in
            func dummy() throws -> [XcodeModuleProtocol] {
                return [try SwiftModule(name: "DummyModuleName", sources: Sources(paths: [], root: dstdir))]
            }

            let projectName = "DummyProjectName"
            let srcroot = dstdir
            let modules = try dummy()
            let products: [Product] = []

            struct Options: XcodeprojOptions {
                let Xcc = [String]()
                let Xld = [String]()
                let Xswiftc = [String]()
                let xcconfigOverrides: String? = nil
            }
            let outpath = try Xcodeproj.generate(dstdir: dstdir, projectName: projectName, srcroot: srcroot, modules: modules, externalModules: [], products: products, options: Options())

            XCTAssertDirectoryExists(outpath)
            XCTAssertEqual(outpath, Path.join(dstdir, "\(projectName).xcodeproj"))

            // Don't allow TOOLCHAINS to be overriden here, as it breaks the test below.
            let output = try popen(["env", "-u", "TOOLCHAINS", "xcodebuild", "-list", "-project", outpath])

            let expectedOutput = "Information about project \"DummyProjectName\":\n    Targets:\n        DummyModuleName\n\n    Build Configurations:\n        Debug\n        Release\n\n    If no build configuration is specified and -scheme is not passed then \"Debug\" is used.\n\n    Schemes:\n        DummyProjectName\n"

            XCTAssertEqual(output, expectedOutput)
        }
    }
}
#endif
{'fraction_non_alphanumeric': 0.10813887307911212, 'fraction_numerical': 0.0037943464238284954, 'mean_word_length': 2.4145077720207255, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1074373', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1486, 'n_words': 464}