瀏覽代碼

Tests/CXXModules: add test case for `import std` support

Ben Boeckel 1 年之前
父節點
當前提交
bf0b457461

+ 6 - 0
Tests/RunCMake/CXXModules/RunCMakeTest.cmake

@@ -175,6 +175,7 @@ endfunction ()
 # - `partitions`: module partitions are supported
 # - `internal_partitions`: internal module partitions are supported
 # - `bmionly`: the compiler supports BMI-only builds
+# - `import_std23`: the compiler supports `import std` for C++23
 #
 # Generator-based:
 # - `compile_commands`: the generator supports `compile_commands.json`
@@ -221,6 +222,11 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
   run_cxx_module_test(same-src-name)
   run_cxx_module_test(scan_properties)
   run_cxx_module_test(target-objects)
+
+  if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
+      "import_std23" IN_LIST CMake_TEST_MODULE_COMPILATION)
+    run_cxx_module_test(import-std)
+  endif ()
 endif ()
 
 # Tests which require compile commands support.

+ 12 - 0
Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_executable(main
+  main.cxx)
+target_compile_features(main PRIVATE cxx_std_23)
+
+add_test(NAME main COMMAND main)

+ 10 - 0
Tests/RunCMake/CXXModules/examples/import-std/main.cxx

@@ -0,0 +1,10 @@
+import std;
+
+int main(int argc, char* argv[])
+{
+  if (argc > 0 && argv[0]) {
+    std::string argv0 = argv[0];
+    std::cout << "program: " << argv0 << std::endl;
+  }
+  return 0;
+}