|
12 | 12 | import XCTest
|
13 | 13 |
|
14 | 14 | @_spi(Testing) import SwiftDriver
|
| 15 | +import class TSCBasic.DiagnosticsEngine |
15 | 16 |
|
16 | 17 | final class TripleTests: XCTestCase {
|
17 | 18 | func testBasics() throws {
|
@@ -1278,6 +1279,130 @@ final class TripleTests: XCTestCase {
|
1278 | 1279 | watchOSVersion: .init(60, 0, 0),
|
1279 | 1280 | shouldHaveJetPacks: true)
|
1280 | 1281 | }
|
| 1282 | + |
| 1283 | + func testToolchainSelection() { |
| 1284 | + let diagnostics = DiagnosticsEngine() |
| 1285 | + struct None { } |
| 1286 | + |
| 1287 | + func assertToolchain<T>( |
| 1288 | + _ rawTriple: String, |
| 1289 | + _ expectedToolchain: T.Type?, |
| 1290 | + file: StaticString = #filePath, |
| 1291 | + line: UInt = #line |
| 1292 | + ) { |
| 1293 | + do { |
| 1294 | + let triple = Triple(rawTriple) |
| 1295 | + let actual = try triple.toolchainType(diagnostics) |
| 1296 | + if None.self is T.Type { |
| 1297 | + XCTFail( |
| 1298 | + "Expected None but found \(actual) for triple \(rawTriple).", |
| 1299 | + file: file, |
| 1300 | + line: line) |
| 1301 | + } else { |
| 1302 | + XCTAssertTrue( |
| 1303 | + actual is T.Type, |
| 1304 | + "Expected \(T.self) but found \(actual) for triple \(rawTriple).", |
| 1305 | + file: file, |
| 1306 | + line: line) |
| 1307 | + } |
| 1308 | + } catch { |
| 1309 | + if None.self is T.Type { |
| 1310 | + // Good |
| 1311 | + } else { |
| 1312 | + XCTFail( |
| 1313 | + "Expected \(T.self) but found None for triple \(rawTriple).", |
| 1314 | + file: file, |
| 1315 | + line: line) |
| 1316 | + } |
| 1317 | + } |
| 1318 | + } |
| 1319 | + |
| 1320 | + assertToolchain("i386-apple-darwin", DarwinToolchain.self) |
| 1321 | + assertToolchain("i386-pc-hurd-gnu", None.self) |
| 1322 | + assertToolchain("x86_64-pc-linux-gnu", GenericUnixToolchain.self) |
| 1323 | + assertToolchain("x86_64-pc-linux-musl", GenericUnixToolchain.self) |
| 1324 | + assertToolchain("powerpc-bgp-linux", GenericUnixToolchain.self) |
| 1325 | + assertToolchain("powerpc-bgp-cnk", None.self) |
| 1326 | + assertToolchain("ppc-bgp-linux", GenericUnixToolchain.self) |
| 1327 | + assertToolchain("ppc32-bgp-linux", GenericUnixToolchain.self) |
| 1328 | + assertToolchain("powerpc64-bgq-linux", GenericUnixToolchain.self) |
| 1329 | + assertToolchain("ppc64-bgq-linux", GenericUnixToolchain.self) |
| 1330 | + assertToolchain("powerpc-ibm-aix", None.self) |
| 1331 | + assertToolchain("powerpc64-ibm-aix", None.self) |
| 1332 | + assertToolchain("powerpc-dunno-notsure", None.self) |
| 1333 | + assertToolchain("arm-none-none-eabi", GenericUnixToolchain.self) |
| 1334 | + assertToolchain("arm-none-unknown-eabi", None.self) |
| 1335 | + assertToolchain("arm-none-linux-musleabi", GenericUnixToolchain.self) |
| 1336 | + assertToolchain("armv6hl-none-linux-gnueabi", GenericUnixToolchain.self) |
| 1337 | + assertToolchain("armv7hl-none-linux-gnueabi", GenericUnixToolchain.self) |
| 1338 | + assertToolchain("amdil-unknown-unknown", None.self) |
| 1339 | + assertToolchain("amdil64-unknown-unknown", None.self) |
| 1340 | + assertToolchain("hsail-unknown-unknown", None.self) |
| 1341 | + assertToolchain("hsail64-unknown-unknown", None.self) |
| 1342 | + assertToolchain("sparcel-unknown-unknown", None.self) |
| 1343 | + assertToolchain("spir-unknown-unknown", None.self) |
| 1344 | + assertToolchain("spir64-unknown-unknown", None.self) |
| 1345 | + assertToolchain("x86_64-unknown-ananas", None.self) |
| 1346 | + assertToolchain("x86_64-unknown-cloudabi", None.self) |
| 1347 | + assertToolchain("x86_64-unknown-fuchsia", None.self) |
| 1348 | + assertToolchain("x86_64-unknown-hermit", None.self) |
| 1349 | + assertToolchain("wasm32-unknown-unknown", None.self) |
| 1350 | + assertToolchain("wasm32-unknown-wasi", WebAssemblyToolchain.self) |
| 1351 | + assertToolchain("wasm64-unknown-unknown", None.self) |
| 1352 | + assertToolchain("wasm64-unknown-wasi", WebAssemblyToolchain.self) |
| 1353 | + assertToolchain("avr-unknown-unknown", None.self) |
| 1354 | + assertToolchain("avr", None.self) |
| 1355 | + assertToolchain("lanai-unknown-unknown", None.self) |
| 1356 | + assertToolchain("lanai", None.self) |
| 1357 | + assertToolchain("amdgcn-mesa-mesa3d", None.self) |
| 1358 | + assertToolchain("amdgcn-amd-amdhsa", None.self) |
| 1359 | + assertToolchain("amdgcn-amd-amdpal", None.self) |
| 1360 | + assertToolchain("riscv32-unknown-unknown", None.self) |
| 1361 | + assertToolchain("riscv64-unknown-linux", GenericUnixToolchain.self) |
| 1362 | + assertToolchain("riscv64-unknown-freebsd", GenericUnixToolchain.self) |
| 1363 | + assertToolchain("armv7hl-suse-linux-gnueabi", GenericUnixToolchain.self) |
| 1364 | + assertToolchain("i586-pc-haiku", GenericUnixToolchain.self) |
| 1365 | + assertToolchain("x86_64-unknown-haiku", GenericUnixToolchain.self) |
| 1366 | + assertToolchain("mips-mti-linux-gnu", GenericUnixToolchain.self) |
| 1367 | + assertToolchain("mipsel-img-linux-gnu", GenericUnixToolchain.self) |
| 1368 | + assertToolchain("mips64-mti-linux-gnu", GenericUnixToolchain.self) |
| 1369 | + assertToolchain("mips64el-img-linux-gnu", GenericUnixToolchain.self) |
| 1370 | + assertToolchain("mips64el-img-linux-gnuabin32", GenericUnixToolchain.self) |
| 1371 | + assertToolchain("mips64el", None.self) |
| 1372 | + assertToolchain("mips64", None.self) |
| 1373 | + assertToolchain("mips64-unknown-linux-gnuabi64", GenericUnixToolchain.self) |
| 1374 | + assertToolchain("mips64-unknown-linux-gnuabin32", GenericUnixToolchain.self) |
| 1375 | + assertToolchain("mipsn32", None.self) |
| 1376 | + assertToolchain("mipsn32r6", None.self) |
| 1377 | + assertToolchain("mipsel-unknown-linux-gnu", GenericUnixToolchain.self) |
| 1378 | + assertToolchain("mipsel", None.self) |
| 1379 | + assertToolchain("mips-unknown-linux-gnu", GenericUnixToolchain.self) |
| 1380 | + assertToolchain("mips", None.self) |
| 1381 | + assertToolchain("mipsr6el", None.self) |
| 1382 | + assertToolchain("mipsisa32r6el", None.self) |
| 1383 | + assertToolchain("mipsisa32r6-unknown-linux-gnu", GenericUnixToolchain.self) |
| 1384 | + assertToolchain("mipsr6", None.self) |
| 1385 | + assertToolchain("mipsisa32r6", None.self) |
| 1386 | + assertToolchain("arm-oe-linux-gnueabi", GenericUnixToolchain.self) |
| 1387 | + assertToolchain("aarch64-oe-linux", GenericUnixToolchain.self) |
| 1388 | + assertToolchain("x86_64-apple-tvos13.0-simulator", DarwinToolchain.self) |
| 1389 | + assertToolchain("arm64_32-apple-ios", DarwinToolchain.self) |
| 1390 | + assertToolchain("armv7s-apple-ios", DarwinToolchain.self) |
| 1391 | + assertToolchain("armv7em-unknown-none-macho", GenericUnixToolchain.self) |
| 1392 | + assertToolchain("armv7em-apple-none-macho", DarwinToolchain.self) |
| 1393 | + assertToolchain("armv7em-apple-none", DarwinToolchain.self) |
| 1394 | + assertToolchain("xscale-none-linux-gnueabi", GenericUnixToolchain.self) |
| 1395 | + assertToolchain("thumbv7-pc-linux-gnu", GenericUnixToolchain.self) |
| 1396 | + assertToolchain("thumbv3-pc-linux-gnu", GenericUnixToolchain.self) |
| 1397 | + assertToolchain("i686-pc-windows-msvc", WindowsToolchain.self) |
| 1398 | + assertToolchain("i686-unknown-windows-msvc", WindowsToolchain.self) |
| 1399 | + assertToolchain("i686-pc-windows-gnu", WindowsToolchain.self) |
| 1400 | + assertToolchain("i686-unknown-windows-gnu", WindowsToolchain.self) |
| 1401 | + assertToolchain("i686-pc-windows-gnu", WindowsToolchain.self) |
| 1402 | + assertToolchain("i686-unknown-windows-gnu", WindowsToolchain.self) |
| 1403 | + assertToolchain("i686-pc-windows-cygnus", WindowsToolchain.self) |
| 1404 | + assertToolchain("i686-unknown-windows-cygnus", WindowsToolchain.self) |
| 1405 | + } |
1281 | 1406 | }
|
1282 | 1407 |
|
1283 | 1408 | extension Triple.Version: ExpressibleByStringLiteral {
|
|
0 commit comments