 // RUN: mkdir -p %t
 // RUN: %target-build-swift %s -parse-stdlib -Xfrontend -disable-access-control -o %t/a.out -Xlinker -dead_strip
-// RUN: %target-run %t/a.out env | FileCheck %s
-// RUN: %target-run %t/a.out ru_RU.UTF-8 | FileCheck %s
+// RUN: %target-run %t/a.out env %s
+// RUN: %target-run %t/a.out ru_RU.UTF-8 %s
 // REQUIRES: executable_test
 
 // XFAIL: linux
 
 import Swift
 import Darwin
-
-// Interpret the command line arguments.
+import StdlibUnittest
+
+let PrintTests = TestSuite("Print")
+
 let arg = Process.arguments[1]
-
 if arg == "env" {
   setlocale(LC_ALL, "")
 } else {
+  expectEqual("ru_RU.UTF-8", arg)
   setlocale(LC_ALL, arg)
 }
-
-import StdlibUnittest
-let PrintTests = TestSuite("Print")
 
 PrintTests.test("stdlib types have description") {
   func hasDescription(any: Any) {

  }
}

func test_CustomStringInterpolation() {
  assertEquals("<segment aaa><segment 1><segment bbb>",
               ("aaa\(1)bbb" as MyString).value)

  print("test_CustomStringInterpolation done")
}
test_CustomStringInterpolation()
// CHECK: test_CustomStringInterpolation done

func test_StdoutUTF8Printing() {
  print("\u{00B5}")
// CHECK: {{^}}µ{{$}}

  print("test_StdoutUTF8Printing done")
}
test_StdoutUTF8Printing()
// CHECK: test_StdoutUTF8Printing done

func test_varargs() {
  print("", 1, 2, 3, 4, "", separator: "|") // CHECK: |1|2|3|4|
  print(1, 2, 3, separator: "\n", terminator: "===")
  print(4, 5, 6, separator: "\n")
  // CHECK-NEXT: 1
  // CHECK-NEXT: 2
  // CHECK-NEXT: 3===4
  // CHECK-NEXT: 5
  // CHECK-NEXT: 6

  debugPrint("", 1, 2, 3, 4, "", separator: "|")
   // CHECK-NEXT: ""|1|2|3|4|""
  debugPrint(1, 2, 3, separator: "\n", terminator: "===")
  debugPrint(4, 5, 6, separator: "\n")
  // CHECK-NEXT: 1
  // CHECK-NEXT: 2
  // CHECK-NEXT: 3===4
  // CHECK-NEXT: 5
  // CHECK-NEXT: 6

  var output = ""
  print(
    "", 1, 2, 3, 4, "", separator: "|", toStream: &output)
  print(output == "|1|2|3|4|\n") // CHECK-NEXT: true
  output = ""
  debugPrint(
    "", 1, 2, 3, 4, "", separator: "|", terminator: "", toStream: &output)
  print(output == "\"\"|1|2|3|4|\"\"") // CHECK-NEXT: true
  print("test_varargs done")
}
test_varargs()
// CHECK: test_varargs done

func test_playgroundPrintHook() {
  
  var printed: String? = nil
  _playgroundPrintHook = { printed = $0 }
  
  print("", 1, 2, 3, 4, "", separator: "|") // CHECK: |1|2|3|4|
  print("%\(printed!)%") // CHECK-NEXT: %|1|2|3|4|
  // CHECK-NEXT: %
  
  printed = nil
  debugPrint("", 1, 2, 3, 4, "", separator: "|")
  // CHECK-NEXT: ""|1|2|3|4|""
  print("%\(printed!)%") // CHECK-NEXT: %""|1|2|3|4|""
  // CHECK-NEXT: %
  
  var explicitStream = ""
  printed = nil
  print("", 1, 2, 3, 4, "", separator: "!", toStream: &explicitStream)
  print(printed)               // CHECK-NEXT: nil
  print("%\(explicitStream)%") // CHECK-NEXT: %!1!2!3!4!
  // CHECK-NEXT: %
  
  explicitStream = ""
  printed = nil
  debugPrint(
    "", 1, 2, 3, 4, "", separator: "!", toStream: &explicitStream)
  print(printed) // CHECK-NEXT: nil
  print("%\(explicitStream)%") // CHECK-NEXT: %""!1!2!3!4!""
  // CHECK-NEXT: %
  
  _playgroundPrintHook = nil
  print("test_playgroundPrintHook done")
  // CHECK-NEXT: test_playgroundPrintHook done
}
test_playgroundPrintHook()

if !failed {
  print("OK")
}
// CHECK: OK


}

PrintTests.test("optional strings") {
  expectPrinted("nil", String!())
  expectPrinted("meow", String!("meow"))
  expectPrinted("nil", String?())
  expectPrinted("Optional(\"meow\")", String?("meow"))
}

PrintTests.test("custom string convertible structs") {
