 // 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) {

}

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

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

    ClassPrintable(2), ClassPrintable(3) ] as Array<AnyObject>)
}

PrintTests.test("Dictionary") {
  expectPrinted("[:]", [String: Int]())
  expectDebugPrinted("[:]", [String: Int]())
  
  expectPrinted("[\"aaa\": 1]", [ "aaa": 1 ])
  expectDebugPrinted("[\"aaa\": 1]", [ "aaa": 1 ])
  
  let d0 = [ "aaa": 1, "bbb": 2 ]
  expectPrinted(expectedOneOf: [ "[\"aaa\": 1, \"bbb\": 2]",
    "[\"bbb\": 2, \"aaa\": 1]" ], d0)
  expectDebugPrinted(expectedOneOf: [ "[\"aaa\": 1, \"bbb\": 2]",
    "[\"bbb\": 2, \"aaa\": 1]" ], d0)
  
  let d1 = [ "aaa": "bbb" ]
  expectPrinted("[\"aaa\": \"bbb\"]", d1)
  expectDebugPrinted("[\"aaa\": \"bbb\"]", d1)
}

PrintTests.test("Set") {
  expectPrinted("[]", Set<Int>())
  expectDebugPrinted("Set([])", Set<Int>())
  
  let s0 = Set<Int>([11, 22])
  expectPrinted(expectedOneOf: [ "[11, 22]", "[22, 11]" ], s0)
  expectDebugPrinted(expectedOneOf: [ "Set([11, 22])",
    "Set([22, 11])" ], s0)
  
  let s1 = Set<String>(["Hello", "world"])
  expectPrinted(expectedOneOf: [ "[\"Hello\", \"world\"]",
    "[\"world\", \"Hello\"]" ], s1)
  expectDebugPrinted(expectedOneOf: [ "Set([\"Hello\", \"world\"])",
    "Set([\"world\", \"Hello\"])" ], s1)
}

PrintTests.test("Tuple") {
  expectPrinted("(42, ())", (42, ()))
  expectPrinted("((), 42)", ((), 42))
  expectPrinted("(42, ►3◀︎)", (42, StructPrintable(3)))
  expectPrinted("(42, <10 20 30 40>)",
    (42, LargeStructPrintable(10, 20, 30, 40)))
  expectPrinted("(42, ►3◀︎)", (42, ClassPrintable(3)))
  expectPrinted("([123: 123], (1, 2, \"3\"))",
    ([123: 123], (1, 2, "3")))
  
  let t0 = [ (1, "two", StructPrintable(3), StructDebugPrintable(4),
    WithoutDescription(5)) ]
  expectPrinted("[(1, \"two\", ►3◀︎, ►4◀︎, a.WithoutDescription(x: 5))]",
    t0)
  
  let t1 = [ (1, "two", WithoutDescription(3)),
    (11, "twenty-two", WithoutDescription(33)),
    (111, "two hundred twenty-two", WithoutDescription(333)) ]
  expectPrinted("[(1, \"two\", a.WithoutDescription(x: 3)), (11, \"twenty-two\", a.WithoutDescription(x: 33)), (111, \"two hundred twenty-two\", a.WithoutDescription(x: 333))]", t1)
}

PrintTests.test("ArbitraryStruct") {
  let s0 = [ WithoutDescription(1), WithoutDescription(2), WithoutDescription(3) ]
  expectPrinted(
  "[a.WithoutDescription(x: 1), a.WithoutDescription(x: 2), a.WithoutDescription(x: 3)]",
  s0)
  expectDebugPrinted(
  "[a.WithoutDescription(x: 1), a.WithoutDescription(x: 2), a.WithoutDescription(x: 3)]",
  s0)
  
  expectPrinted("EmptyStructWithoutDescription()",
    EmptyStructWithoutDescription())
  expectDebugPrinted("a.EmptyStructWithoutDescription()",
    EmptyStructWithoutDescription())
  
  expectPrinted(
    "ValuesWithoutDescription<Double, String, Array<Int>>(t: 1.25, u: \"abc\", v: [1, 2, 3])",
    ValuesWithoutDescription(1.25, "abc", [ 1, 2, 3 ]))
  expectDebugPrinted(
    "a.ValuesWithoutDescription<Swift.Double, Swift.String, Swift.Array<Swift.Int>>(t: 1.25, u: \"abc\", v: [1, 2, 3])", ValuesWithoutDescription(1.25, "abc", [ 1, 2, 3 ]))
}

PrintTests.test("Metatype") {
  expectPrinted("Int", Int.self)
  expectDebugPrinted("Swift.Int", Int.self)
}

PrintTests.test("StringInterpolation") {
  expectEqual("1", "\(1)")
  expectEqual("2", "\(1 + 1)")
  expectEqual("aaa1bbb2ccc", "aaa\(1)bbb\(2)ccc")
  
  expectEqual("1.0", "\(1.0)")
  expectEqual("1.5", "\(1.5)")
  expectEqual("1e-12", "\(1.0 / (1000000000000))")
  
  expectEqual("inf", "\(1 / 0.0)")
  expectEqual("-inf", "\(-1 / 0.0)")
  expectEqual("nan", "\(0 / 0.0)")
  
  expectEqual("<[►1◀︎, ►2◀︎, ►3◀︎]>", "<\([ StructPrintable(1), StructPrintable(2), StructPrintable(3) ])>")
  expectEqual("WithoutDescription(x: 1)", "\(WithoutDescription(1))")
}

struct MyString : StringLiteralConvertible, StringInterpolationConvertible {
  init(str: String) {
