From e1ed229e515f94293685b3bd11a59c4a126e3c6a Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Mon, 25 Apr 2016 15:20:15 -0400 Subject: [PATCH] [IRGen] Rewrite dead method test in StdlibUnittest StdlibUnitest is the preferred system for testing that a certain piece of code crashes. It's also the only way to get this test to pass when run on an Android host device, since otherwise the device test runner exits before confirming the output via FileCheck. --- .../Inputs/report_dead_method_call/main.swift | 28 +++++++++++++------ test/IRGen/report_dead_method_call.swift | 20 ++++++------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/test/IRGen/Inputs/report_dead_method_call/main.swift b/test/IRGen/Inputs/report_dead_method_call/main.swift index dff2b7d9294c2..ca35bdd3f3b55 100644 --- a/test/IRGen/Inputs/report_dead_method_call/main.swift +++ b/test/IRGen/Inputs/report_dead_method_call/main.swift @@ -1,4 +1,8 @@ +// The StdlibUnittest test suite is placed here because it contains +// expressions that are only allowed at the top level in files named +// "main.swift". +import StdlibUnittest @inline(never) func testProto(_ c: Container) { @@ -27,16 +31,22 @@ func testPublicClass(_ c: PublicBase) { c.ghi() } -switch Process.argc { -case 1: - callClass() +let ReportDeadMethodCallTestSuite = TestSuite("ReportDeadMethodCall") -case 2: - callProto() +ReportDeadMethodCallTestSuite.test("Call class") { + expectCrashLater() + callClass() +} -case 3: - callPublicClass() +ReportDeadMethodCallTestSuite.test("Call proto") { + expectCrashLater() + callProto() +} -default: - break +ReportDeadMethodCallTestSuite.test("Call public class") { + expectCrashLater() + callPublicClass() } + +runAllTests() + diff --git a/test/IRGen/report_dead_method_call.swift b/test/IRGen/report_dead_method_call.swift index abce2943de59e..1f65efe6c622c 100644 --- a/test/IRGen/report_dead_method_call.swift +++ b/test/IRGen/report_dead_method_call.swift @@ -1,15 +1,15 @@ -// RUN: rm -rf %t && mkdir -p %t -// RUN: %target-build-swift %S/Inputs/report_dead_method_call/main.swift %s -O -Xfrontend -disable-access-control -o %t/a.out -// RUN: %target-run %t/a.out 2> %t/err1.log; FileCheck %s < %t/err1.log -// RUN: %target-run %t/a.out p1 2> %t/err2.log; FileCheck %s < %t/err2.log -// RUN: %target-run %t/a.out p1 p2 2> %t/err3.log; FileCheck %s < %t/err3.log -// REQUIRES: executable_test - +// RUN: rm -rf %t +// RUN: mkdir -p %t -// The -disable-access-control option let us "call" methods, which are removed -// by dead method elimination. +// We compile with -O (optimizations) and -disable-access-control (which +// allows use to "call" methods that are removed by dead code elimination). +// RUN: %target-build-swift %S/Inputs/report_dead_method_call/main.swift %s -O -Xfrontend -disable-access-control -o %t/report_dead_method_call -// CHECK: fatal error: call of deleted method +// The private, unused methods are optimized away. The test calls these +// methods anyway (since it has overridden the access control), so we +// expect them to produce "fatal error: call of deleted method" when run. +// RUN: %target-run %t/report_dead_method_call +// REQUIRES: executable_test private protocol PrivateProto { func abc()