Skip to content

Commit cccb21a

Browse files
committed
[driver] Add test for new behaviour in createCompilerInvocation
Test for "ForceNoOutputs" flag.
1 parent ffc990f commit cccb21a

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

test/Driver/createCompilerInvocation.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,29 @@
77

88
// CHECK-FAIL: error: unable to create a CompilerInvocation
99
// CHECK-NOWARN-NOT: warning
10+
11+
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library %s 2>&1 | %FileCheck %s --check-prefix=NORMAL_ARGS --implicit-check-not="error: "
12+
// NORMAL_ARGS: Frontend Arguments BEGIN
13+
// NORMAL_ARGS-DAG: -o{{$}}
14+
// NORMAL_ARGS-DAG: foo-{{[a-z0-9]+}}.o
15+
// NORMAL_ARGS-DAG: -c{{$}}
16+
// NORMAL_ARGS-DAG: -module-name
17+
// NORMAL_ARGS-DAG: -emit-module-path
18+
// NORMAL_ARGS-DAG: -emit-module-doc-path
19+
// NORMAL_ARGS-DAG: -emit-module-source-info-path
20+
// NORMAL_ARGS-DAG: -emit-module-interface-path
21+
// NORMAL_ARGS-DAG: -emit-objc-header-path
22+
// NORMAL_ARGS: Frontend Arguments END
23+
24+
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -force-no-outputs -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library %s 2>&1 > %t.nooutput_args
25+
// RUN: %FileCheck %s --check-prefix=NOOUTPUT_ARGS --implicit-check-not="error: " < %t.nooutput_args
26+
// RUN: %FileCheck %s --check-prefix=NOOUTPUT_ARGS_NEG --implicit-check-not="error: " < %t.nooutput_args
27+
// NOOUTPUT_ARGS_NEG-NOT: -o{{$}}
28+
// NOOUTPUT_ARGS_NEG-NOT: foo-{{[a-z0-9]+}}.o
29+
// NOOUTPUT_ARGS_NEG-NOT: -o{{$}}
30+
// NOOUTPUT_ARGS_NEG-NOT: -emit
31+
32+
// NOOUTPUT_ARGS: Frontend Arguments BEGIN
33+
// NOOUTPUT_ARGS-DAG: -typecheck
34+
// NOOUTPUT_ARGS-DAG: -module-name
35+
// NOOUTPUT_ARGS: Frontend Arguments END

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@ static int doPrintUSRs(const CompilerInvocation &InitInvok,
32233223
return 0;
32243224
}
32253225

3226-
static int doTestCreateCompilerInvocation(ArrayRef<const char *> Args) {
3226+
static int doTestCreateCompilerInvocation(ArrayRef<const char *> Args, bool ForceNoOutputs) {
32273227
PrintingDiagnosticConsumer PDC;
32283228
SourceManager SM;
32293229
DiagnosticEngine Diags(SM);
@@ -3232,8 +3232,13 @@ static int doTestCreateCompilerInvocation(ArrayRef<const char *> Args) {
32323232
CompilerInvocation CI;
32333233
bool HadError = driver::getSingleFrontendInvocationFromDriverArguments(
32343234
Args, Diags, [&](ArrayRef<const char *> FrontendArgs) {
3235+
llvm::outs() << "Frontend Arguments BEGIN\n";
3236+
for (const char *arg : FrontendArgs) {
3237+
llvm::outs() << arg << "\n";
3238+
}
3239+
llvm::outs() << "Frontend Arguments END\n";
32353240
return CI.parseArgs(FrontendArgs, Diags);
3236-
});
3241+
}, ForceNoOutputs);
32373242

32383243
if (HadError) {
32393244
llvm::errs() << "error: unable to create a CompilerInvocation\n";
@@ -3271,8 +3276,13 @@ int main(int argc, char *argv[]) {
32713276
// llvm::cl::ParseCommandLineOptions.
32723277
StringRef FirstArg(argv[1]);
32733278
if (FirstArg == "-test-createCompilerInvocation") {
3279+
bool ForceNoOutputs = false;
32743280
ArrayRef<const char *> Args(argv + 2, argc - 2);
3275-
return doTestCreateCompilerInvocation(Args);
3281+
if (argc > 2 && StringRef(argv[2]) == "-force-no-outputs") {
3282+
ForceNoOutputs = true;
3283+
Args = Args.drop_front();
3284+
}
3285+
return doTestCreateCompilerInvocation(Args, ForceNoOutputs);
32763286
}
32773287
}
32783288

0 commit comments

Comments
 (0)