 import XCTest
 import TestUtilities
 
+private func executableName(_ name: String) -> String {
+#if os(Windows)
+  if name.count > 4, name.suffix(from: name.index(name.endIndex, offsetBy: -4)) == ".exe" {
+    return name
+  }
+  return "\(name).exe"
+#else
+  return name
+#endif
+}
+
 final class SwiftDriverTests: XCTestCase {
 
   private var envWithFakeSwiftHelp: [String: String] {

      XCTAssertTrue(matchTemporary(plannedJobs[2].outputs.first!.file, "foo5.o"))
      XCTAssertTrue(plannedJobs[3].tool.name.contains(driver1.targetTriple.isDarwin ? "ld" : "clang"))
      XCTAssertEqual(plannedJobs[3].outputs.count, 1)
      XCTAssertEqual(plannedJobs[3].outputs.first!.file, VirtualPath.relative(RelativePath("Test")))
    }

    // Test 1 partition results in 1 job

    var output = ""
    serializer.writeDOT(to: &output)

    let linkerDriver = driver.targetTriple.isDarwin ? executableName("ld") : executableName("clang")
    #if os(Linux) || os(Android)
    XCTAssertEqual(output,
    """
    digraph Jobs {
      "emitModule (\(executableName("swift-frontend")))" [style=bold];
      "test.swift" [fontsize=12];
      "test.swift" -> "emitModule (\(executableName("swift-frontend")))" [color=blue];
      "test.swiftmodule" [fontsize=12];
      "emitModule (\(executableName("swift-frontend")))" -> "test.swiftmodule" [color=green];
      "test.swiftdoc" [fontsize=12];
      "emitModule (\(executableName("swift-frontend")))" -> "test.swiftdoc" [color=green];
      "test.abi.json" [fontsize=12];
      "emitModule (\(executableName("swift-frontend")))" -> "test.abi.json" [color=green];
      "compile (\(executableName("swift-frontend")))" [style=bold];
      "test.swift" -> "compile (\(executableName("swift-frontend")))" [color=blue];
      "test-1.o" [fontsize=12];
      "compile (\(executableName("swift-frontend")))" -> "test-1.o" [color=green];
      "autolinkExtract (\(executableName("swift-autolink-extract")))" [style=bold];
      "test-1.o" -> "autolinkExtract (\(executableName("swift-autolink-extract")))" [color=blue];
      "test-2.autolink" [fontsize=12];
      "autolinkExtract (\(executableName("swift-autolink-extract")))" -> "test-2.autolink" [color=green];
      "link (\(executableName("clang")))" [style=bold];
      "test-1.o" -> "link (\(executableName("clang")))" [color=blue];
      "test-2.autolink" -> "link (\(executableName("clang")))" [color=blue];
      "\(executableName("test"))" [fontsize=12];
      "link (\(executableName("clang")))" -> "\(executableName("test"))" [color=green];
    }

    """)
