Skip to content

Commit 39d3963

Browse files
committed
Fix broken tests
- Many tests got broken because of two things: - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix. - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence. Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
1 parent ea0ca11 commit 39d3963

20 files changed

+42
-33
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,15 +687,24 @@ static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation,
687687

688688
/// Dumps the AST of all available primary source files. If corresponding output
689689
/// files were specified, use them; otherwise, dump the AST to stdout.
690-
static void dumpAST(CompilerInstance &Instance) {
690+
static void dumpAST(CompilerInvocation &Invocation,
691+
CompilerInstance &Instance) {
691692
// FIXME: WMO doesn't use the notion of primary files, so this doesn't do the
692693
// right thing. Perhaps it'd be best to ignore WMO when dumping the AST, just
693694
// like WMO ignores `-incremental`.
694-
for (SourceFile *sourceFile: Instance.getPrimarySourceFiles()) {
695-
const StringRef OutputFilename =
696-
Instance.getPrimarySpecificPathsForSourceFile(*sourceFile).OutputFilename;
697-
auto OS = getFileOutputStream(OutputFilename, Instance.getASTContext());
698-
sourceFile->dump(*OS);
695+
696+
auto primaryFiles = Instance.getPrimarySourceFiles();
697+
if (!primaryFiles.empty()) {
698+
for (SourceFile *sourceFile: primaryFiles) {
699+
auto PSPs = Instance.getPrimarySpecificPathsForSourceFile(*sourceFile);
700+
auto OutputFilename = PSPs.OutputFilename;
701+
auto OS = getFileOutputStream(OutputFilename, Instance.getASTContext());
702+
sourceFile->dump(*OS);
703+
}
704+
} else {
705+
// Some invocations don't have primary files. In that case, we default to
706+
// looking for the main file and dumping it to `stdout`.
707+
getPrimaryOrMainSourceFile(Invocation, Instance)->dump(llvm::outs());
699708
}
700709
}
701710

@@ -742,7 +751,7 @@ static Optional<bool> dumpASTIfNeeded(CompilerInvocation &Invocation,
742751

743752
case FrontendOptions::ActionType::DumpParse:
744753
case FrontendOptions::ActionType::DumpAST:
745-
dumpAST(Instance);
754+
dumpAST(Invocation, Instance);
746755
break;
747756

748757
case FrontendOptions::ActionType::EmitImportedModules:

test/Driver/filelists.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
// CHECK-NOT: Handled
77
// CHECK: Handled a.swift
88
// CHECK-NEXT: Supplementary "./a.swift":
9-
// CHECK-NEXT: Supplementary swiftdoc: "./a.swiftdoc"
109
// CHECK-NEXT: Supplementary swiftmodule: "./a.swiftmodule"
10+
// CHECK-NEXT: Supplementary swiftdoc: "./a.swiftdoc"
1111
// CHECK-NEXT: Handled b.swift
1212
// CHECK-NEXT: Supplementary "./b.swift":
13-
// CHECK-NEXT: Supplementary swiftdoc: "./b.swiftdoc"
1413
// CHECK-NEXT: Supplementary swiftmodule: "./b.swiftmodule"
14+
// CHECK-NEXT: Supplementary swiftdoc: "./b.swiftdoc"
1515
// CHECK-NEXT: Handled c.swift
1616
// CHECK-NEXT: Supplementary "./c.swift":
17-
// CHECK-NEXT: Supplementary swiftdoc: "./c.swiftdoc"
1817
// CHECK-NEXT: Supplementary swiftmodule: "./c.swiftmodule"
18+
// CHECK-NEXT: Supplementary swiftdoc: "./c.swiftdoc"
1919
// CHECK-NEXT: Handled modules
2020
// CHECK-NOT: Handled
2121

test/Frontend/dump-parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: not %target-swift-frontend -dump-parse %s 2>&1 | %FileCheck %s
2-
// RUN: not %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s -check-prefix=CHECK-AST
2+
// RUN: not %target-swift-frontend -dump-ast %s | %FileCheck %s -check-prefix=CHECK-AST
33

44
// CHECK-LABEL: (func_decl{{.*}}"foo(_:)"
55
// CHECK-AST-LABEL: (func_decl{{.*}}"foo(_:)"
@@ -73,4 +73,4 @@ func nonescaping(_: (Int) -> Int) {}
7373
nonescaping({ $0 })
7474
// CHECK-AST: (declref_expr type='((Int) -> Int) -> ()'
7575
// CHECK-AST-NEXT: (paren_expr
76-
// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=1 single-expression
76+
// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=1 single-expression

test/NameBinding/import-resolution-overload.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/overload_vars.swift
55
// RUN: %target-swift-frontend -typecheck %s -I %t -sdk "" -verify
66

7-
// RUN: not %target-swift-frontend -dump-ast %s -I %t -sdk "" > %t.astdump 2>&1
7+
// RUN: not %target-swift-frontend -dump-ast %s -I %t -sdk "" > %t.astdump
88
// RUN: %FileCheck %s < %t.astdump
99

1010
import overload_intFunctions

test/Parse/if_expr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22

33
// CHECK: (func_decl{{.*}}"r13756261(_:_:)"
44
func r13756261(_ x: Bool, _ y: Int) -> Int {

test/Parse/multiline_normalize_newline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-parse %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-parse %s | %FileCheck %s
22

33
// CR
44
_ = """"""

test/Parse/multiline_string.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22

33
import Swift
44

test/Parse/raw_string.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck --strict-whitespace %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck --strict-whitespace %s
22

33
import Swift
44

test/attr/attr_fixed_layout.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swift-frontend -typecheck -swift-version 4.2 -verify -dump-ast -enable-resilience %s 2>&1 | %FileCheck --check-prefix=RESILIENCE-ON %s
2-
// RUN: %target-swift-frontend -typecheck -swift-version 4.2 -verify -dump-ast -enable-resilience -enable-testing %s 2>&1 | %FileCheck --check-prefix=RESILIENCE-ON %s
3-
// RUN: not %target-swift-frontend -typecheck -swift-version 4.2 -dump-ast %s 2>&1 | %FileCheck --check-prefix=RESILIENCE-OFF %s
4-
// RUN: not %target-swift-frontend -typecheck -swift-version 4.2 -dump-ast %s -enable-testing 2>&1 | %FileCheck --check-prefix=RESILIENCE-OFF %s
1+
// RUN: %target-swift-frontend -typecheck -swift-version 4.2 -verify -dump-ast -enable-resilience %s | %FileCheck --check-prefix=RESILIENCE-ON %s
2+
// RUN: %target-swift-frontend -typecheck -swift-version 4.2 -verify -dump-ast -enable-resilience -enable-testing %s | %FileCheck --check-prefix=RESILIENCE-ON %s
3+
// RUN: not %target-swift-frontend -typecheck -swift-version 4.2 -dump-ast %s | %FileCheck --check-prefix=RESILIENCE-OFF %s
4+
// RUN: not %target-swift-frontend -typecheck -swift-version 4.2 -dump-ast %s -enable-testing | %FileCheck --check-prefix=RESILIENCE-OFF %s
55

66
//
77
// Public types with @_fixed_layout are always fixed layout

test/attr/attr_native_dynamic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -swift-version 5 -typecheck -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -swift-version 5 -typecheck -dump-ast %s | %FileCheck %s
22

33
struct Strukt {
44
// CHECK: (struct_decl {{.*}} "Strukt"

test/decl/protocol/associated_type_overrides.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -typecheck -dump-ast %s | %FileCheck %s
22

33
protocol P1 {
44
associatedtype A

test/decl/protocol/conforms/nscoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
22
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -disable-nskeyedarchiver-diagnostics 2>&1 | %FileCheck -check-prefix CHECK-NO-DIAGS %s
33

4-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -dump-ast 2> %t.ast
4+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -dump-ast > %t.ast
55
// RUN: %FileCheck %s < %t.ast
66

77
// REQUIRES: objc_interop

test/decl/protocol/conforms/nscoding_availability_osx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -target x86_64-apple-macosx10.50 -verify
22

3-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -target x86_64-apple-macosx10.50 -dump-ast 2> %t.ast
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -target x86_64-apple-macosx10.50 -dump-ast > %t.ast
44
// RUN: %FileCheck %s < %t.ast
55

66
// REQUIRES: objc_interop

test/decl/protocol/override.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -dump-ast > %t.ast 2>&1
1+
// RUN: %target-typecheck-verify-swift -dump-ast > %t.ast
22
// RUN: %FileCheck %s < %t.ast
33

44
// Test overriding of protocol members.

test/expr/capture/dynamic_self.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22

33
// CHECK: func_decl{{.*}}"clone()" interface type='(Android) -> () -> Self'
44

test/expr/capture/generic_params.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22

33
func doSomething<T>(_ t: T) {}
44

test/expr/capture/nested.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22

33
// CHECK: func_decl{{.*}}"foo2(_:)"
44
func foo2(_ x: Int) -> (Int) -> (Int) -> Int {

test/expr/capture/top-level-guard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
22
// RUN: %target-swift-frontend -emit-ir %s > /dev/null
33

4-
// RUN: %target-swift-frontend -dump-ast -DVAR %s 2>&1 | %FileCheck %s
4+
// RUN: %target-swift-frontend -dump-ast -DVAR %s | %FileCheck %s
55
// RUN: %target-swift-frontend -emit-ir -DVAR %s > /dev/null
66

77
// CHECK: (top_level_code_decl

test/expr/cast/array_downcast_Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// FIXME: END -enable-source-import hackaround
77

88
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -typecheck %s -verify
9-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -dump-ast -verify 2>&1 | %FileCheck %s
9+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -dump-ast -verify | %FileCheck %s
1010

1111
// REQUIRES: objc_interop
1212

test/expr/primary/literal/collection_upcast_opt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -dump-ast 2> %t.ast
1+
// RUN: %target-typecheck-verify-swift -dump-ast > %t.ast
22
// RUN: %FileCheck %s < %t.ast
33

44
// Verify that upcasts of array literals upcast the individual elements in place

0 commit comments

Comments
 (0)