PackageTests.swift 3.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// 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 Foundation
import atpkg

class PackageTests: Test {
    required init() {}
    let tests = [
22
        PackageTests.testBasic,
Drew's avatar
Drew committed
23 24
        PackageTests.testImport,
        PackageTests.testMixins
25 26 27 28 29
    ]

    let filename = __FILE__
    
    static func testBasic() throws {
Drew's avatar
Drew committed
30
        let filepath = "./tests/collateral/basic.atpkg"
31 32 33 34 35 36

        guard let parser = Parser(filepath: filepath) else {
            try test.assert(false); return
        }
        
        let result = try parser.parse()
37
        guard let package = Package(type: result, configurations: [:], pathOnDisk: "./tests/collateral") else { try test.assert(false); return }
38 39 40 41 42 43 44 45
        
        try test.assert(package.name == "basic")
        try test.assert(package.version == "0.1.0-dev")
        
        try test.assert(package.tasks.count == 1)
        for (key, task) in package.tasks {
            try test.assert(key == "build")
            try test.assert(task.tool == "lldb-build")
46 47 48 49 50
            try test.assert(task["name"]?.string == "json-swift")
            try test.assert(task["output-type"]?.string == "lib")
            try test.assert(task["source"]?.vector?.count == 2)
            try test.assert(task["source"]?.vector?[0].string == "src/**.swift")
            try test.assert(task["source"]?.vector?[1].string == "lib/**.swift")
51 52
        }
    }
53 54 55

    static func testImport() throws {
        let filepath = "./tests/collateral/import_src.atpkg"
56
        guard let package = Package(filepath: filepath, configurations: [:]) else { print("error"); try test.assert(false); return }
57 58

        try test.assert(package.tasks["import_dst.build"] != nil)
Drew's avatar
Drew committed
59
        try test.assert(package.tasks["import_dst.build"]!.importedPath == "./tests/collateral/")
60
    }
Drew's avatar
Drew committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74

    static func testMixins() throws {
        let filepath = "./tests/collateral/mixins.atpkg"
        guard let package = Package(filepath: filepath, configurations: [:]) else { print("error"); try test.assert(false); return }
        guard let compileOptions = package.tasks["build"]?["compileOptions"]?.vector else {
            fatalError("No compile options?")
        }
        try test.assert(compileOptions.count == 4)
        try test.assert(compileOptions[0].string == "-D")
        try test.assert(compileOptions[1].string == "AWESOME")
        try test.assert(compileOptions[2].string == "-D")
        try test.assert(compileOptions[3].string == "MORE_AWESOME")

        guard let package2 = Package(filepath: filepath, configurations: ["awesome":"most"]) else { print("error"); try test.assert(false); return }
Drew's avatar
Drew committed
75
        guard let compileOptions2 = package2.tasks["build"]?["compileOptions"]?.vector else {
Drew's avatar
Drew committed
76 77
            fatalError("no compile options?")
        }
Drew's avatar
Drew committed
78 79 80 81 82 83 84
        try test.assert(compileOptions2.count == 6)
        try test.assert(compileOptions2[0].string == "-D")
        try test.assert(compileOptions2[1].string == "AWESOME")
        try test.assert(compileOptions2[2].string == "-D")
        try test.assert(compileOptions2[3].string == "MORE_AWESOME")
        try test.assert(compileOptions2[4].string == "-D")
        try test.assert(compileOptions2[5].string == "MOST_AWESOME")
Drew's avatar
Drew committed
85 86

    }
87
}