// RUN: rm -rf %t
// RUN: mkdir -p %t
+// RUN: split-file %s %t
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=0 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu1.cpp \
// RUN: -o %t/B.pcm
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu2.cpp \
// RUN: -o %t/C.pcm
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu3.cpp \
// RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/AOK1.pcm
-// RUN: %clang_cc1 -std=c++20 -S -D TU=3 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu4.cpp \
// RUN: -fmodule-file=%t/AOK1.pcm -o %t/tu_3.s -verify
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu5.cpp \
// RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/BC.pcm -verify
-// RUN: %clang_cc1 -std=c++20 -S -D TU=5 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu6.cpp \
// RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/tu_5.s -verify
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=6 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu7.cpp \
// RUN: -fmodule-file=%t/B.pcm -o %t/D.pcm -verify
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=7 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu8.cpp \
// RUN: -fmodule-file=%t/B.pcm -o %t/D.pcm -verify
-// RUN: %clang_cc1 -std=c++20 -S -D TU=8 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu9.cpp \
// RUN: -fmodule-file=%t/B.pcm -o %t/tu_8.s -verify
-// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=9 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu10.cpp \
// RUN: -o %t/B.pcm -verify
-// RUN: %clang_cc1 -std=c++20 -emit-obj -D TU=10 -x c++ %s \
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/import-diags-tu11.cpp \
// RUN: -fmodule-file=%t/C.pcm -o %t/impl.o
// Test diagnostics for incorrect module import sequences.
-#if TU == 0
+//--- import-diags-tu1.cpp
export module B;
// expected-no-diagnostics
-#elif TU == 1
+//--- import-diags-tu2.cpp
export module C;
// expected-no-diagnostics
-#elif TU == 2
+//--- import-diags-tu3.cpp
export module AOK1;
// expected-no-diagnostics
-#elif TU == 3
+//--- import-diags-tu4.cpp
module;
int theAnswer () { return 42; }
-#elif TU == 4
+//--- import-diags-tu5.cpp
export module BC;
import C; // expected-error {{imports must immediately follow the module declaration}}
-#elif TU == 5
+//--- import-diags-tu6.cpp
module B; // implicitly imports B.
import C; // expected-error {{imports must immediately follow the module declaration}}
-#elif TU == 6
+//--- import-diags-tu7.cpp
module;
// We can only have preprocessor commands here, which could include an include
int delta ();
-#elif TU == 7
+//--- import-diags-tu8.cpp
export module D;
import B; // expected-error {{module imports cannot be in the private module fragment}}
-#elif TU == 8
+//--- import-diags-tu9.cpp
module B;
import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
-#elif TU == 9
+//--- import-diags-tu10.cpp
export module B;
import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
-#elif TU == 10
+//--- import-diags-tu11.cpp
int x;
int baz() { return 6174; }
// expected-no-diagnostics
-
-#else
-#error "no MODE set"
-#endif