summaryrefslogtreecommitdiff
path: root/swift/test/TestDriver/macOS/main.swift
blob: 067669642c0197831c9fddfd60ab8014817aadd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Foundation
import PromiseKit
import TestCommon

PromiseKit.conf.Q.map = .global()
PromiseKit.conf.Q.return = .global()
PromiseKit.conf.logHandler = { _ in }

var args = CommandLine.arguments
if args.count < 3 {
    print("Usage: \(CommandLine.arguments[0]) <test> <args>")
    exit(1)
}

do {
    var bundleName = args[1].split(separator: ".").map {
        if let c = $0.first {
            return c.uppercased() + $0.dropFirst()
        } else {
            return String($0)
        }
    }.joined(separator: "")

    let exe = args[2]
    if exe == "ServerAMD" {
        bundleName += "AMD"
    }

    let path = "\(Bundle.main.bundlePath)/../\(bundleName).bundle"

    guard let bundle = Bundle(url: URL(fileURLWithPath: path)) else {
        print("Bundle: `\(path)' not found")
        exit(1)
    }

    let className = "\(bundleName).\(exe)"
    guard let helperClass = bundle.classNamed(className) as? TestHelperI.Type else {
        print("test: `\(className)' not found")
        exit(1)
    }

    let testHelper = helperClass.init()
    args.removeFirst(3)
    try testHelper.run(args: args)

} catch {
    for s in Thread.callStackSymbols {
        print(s)
    }
    print("Error \(error)")
    exit(1)
}