 let fooSel = "foo"
 let barSel = "bar"
 
-// CHECK_NOTHING: ---Begin 
-// CHECK_WARNINGS: ---Begin 
-// CHECK_CRASH: ---Begin 
-fputs("---Begin\n", stderr)
+var shouldCrash = CommandLine.arguments.contains("-expect-crash")
 
-// CHECK_WARNINGS: ***Swift runtime: entrypoint -[a.MyClass foo] generated by implicit @objc inference is deprecated and will be removed in Swift 4
-// CHECK_CRASH: ***Swift runtime: entrypoint -[a.MyClass foo] generated by implicit @objc inference is deprecated and will be removed in Swift 4
-x.perform(Selector(fooSel))
+DeprecatedObjCInferenceTestSuite.test("messagingObjCInference") {
+	// Note whether we're expecting to crash.
+  if shouldCrash { expectCrashLater() }
+	
+	// CHECK_NOTHING: ---Begin 
+	// CHECK_WARNINGS: ---Begin 
+	// CHECK_CRASH: ---Begin 
+	fputs("---Begin\n", stderr)
 
-// CHECK_WARNINGS: ***Swift runtime: entrypoint +[a.MyClass bar] generated by implicit @objc inference is deprecated and will be removed in Swift 4
-type(of: x).perform(Selector(barSel))
+	// CHECK_WARNINGS: ***Swift runtime: entrypoint -[a.MyClass foo] generated by implicit @objc inference is deprecated and will be removed in Swift 4
+	// CHECK_CRASH: ***Swift runtime: entrypoint -[a.MyClass foo] generated by implicit @objc inference is deprecated and will be removed in Swift 4
+	x.perform(Selector(fooSel))
 
-// CHECK_NOTHING-NEXT: ---End 
-// CHECK_WARNINGS: ---End 
-// CHECK_CRASH-NOT: ---End
-fputs("---End\n", stderr)
+	// CHECK_WARNINGS: ***Swift runtime: entrypoint +[a.MyClass bar] generated by implicit @objc inference is deprecated and will be removed in Swift 4
+	type(of: x).perform(Selector(barSel))
+
+	// CHECK_NOTHING-NEXT: ---End 
+	// CHECK_WARNINGS: ---End 
+	// CHECK_CRASH-NOT: ---End
+	fputs("---End\n", stderr)
+}
+
+runAllTests()
+

import Foundation
import Darwin

// var ObjCFailableInitTestSuite = TestSuite("ObjCFailableInit")

class MyClass : NSObject {
  func foo() { }

// RUN: rm -rf %t  &&  mkdir -p %t
// RUN: %target-build-swift %s -o %t/a.out
// RUN: %target-run %t/a.out 2>&1 | %FileCheck %s -check-prefix=CHECK_NOTHING
// RUN: env SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=0 SIMCTL_CHILD_SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=0 %target-run %t/a.out 2>&1 | %FileCheck %s -check-prefix=CHECK_NOTHING

// RUN: env SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=1 SIMCTL_CHILD_SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2 %target-run %t/a.out > %t/level1.log 2>&1
// RUN: %FileCheck %s -check-prefix=CHECK_WARNINGS < %t/level1.log

// RUN: env SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2 SIMCTL_CHILD_SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2 %target-run %t/a.out > %t/level2.log 2>&1
// RUN: %FileCheck %s -check-prefix=CHECK_WARNINGS < %t/level2.log

// RUN: SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=3 SIMCTL_CHILD_SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=3 %target-run %t/a.out -expect-crash > %t/level3.log 2>&1
// RUN: %FileCheck %s -check-prefix=CHECK_CRASH < %t/level3.log

// REQUIRES: executable_test
