[clang][deps] Fix fragile test
authorJan Svoboda <jan_svoboda@apple.com>
Wed, 27 Oct 2021 11:57:35 +0000 (13:57 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Wed, 27 Oct 2021 12:00:13 +0000 (14:00 +0200)
This test was failing on GreenDragon.

clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template [moved from clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template with 50% similarity]
clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template [new file with mode: 0644]
clang/test/ClangScanDeps/modules-context-hash.c

@@ -3,10 +3,5 @@
     "directory": "DIR",
     "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/a -o DIR/tu_a.o",
     "file": "DIR/tu.c"
-  },
-  {
-    "directory": "DIR",
-    "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/b -o DIR/tu_b.o",
-    "file": "DIR/tu.c"
   }
 ]
diff --git a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
new file mode 100644 (file)
index 0000000..3a4ec35
--- /dev/null
@@ -0,0 +1,7 @@
+[
+  {
+    "directory": "DIR",
+    "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/b -o DIR/tu_b.o",
+    "file": "DIR/tu.c"
+  }
+]
index 0b9a3e0..dfa3328 100644 (file)
@@ -5,9 +5,17 @@
 // a single translation unit gets compiled with multiple command-lines that
 // produce different **strict** context hashes.
 
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb.json.template > %t/cdb.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_a.json.template > %t/cdb_a.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b.json.template > %t/cdb_b.json
+
+// We run two separate scans. The context hash for "a" and "b" can differ between
+// systems. If we'd scan both Clang invocations in a single run, the order of JSON
+// entities would be non-deterministic. To prevent this, run the scans separately
+// and verify that the context hashes differ with a single FileCheck invocation.
+//
 // RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -j 1 >> %t/result.json
 // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -check-prefix=CHECK
 
 // CHECK:      -[[PREFIX:.*]]
 // CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "name": "mod"
-// CHECK-NEXT:     },
-// CHECK-NEXT:     {
-// CHECK-NEXT:       "clang-module-deps": [],
-// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
-// CHECK-NEXT:       "command-line": [
-// CHECK-NEXT:         "-cc1"
-// CHECK:              "-emit-module"
-// CHECK:              "-I"
-// CHECK:              "[[PREFIX]]/b"
-// CHECK:              "-fmodule-name=mod"
-// CHECK:            ],
-// CHECK-NEXT:       "context-hash": "[[HASH_MOD_B:.*]]",
-// CHECK-NEXT:       "file-deps": [
-// CHECK-NEXT:         "[[PREFIX]]/b/dep.h",
-// CHECK-NEXT:         "[[PREFIX]]/mod.h",
-// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
-// CHECK-NEXT:       ],
-// CHECK-NEXT:       "name": "mod"
 // CHECK-NEXT:     }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "translation-units": [
 // CHECK-NEXT:         "[[PREFIX]]/tu.c"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "input-file": "[[PREFIX]]/tu.c"
-// CHECK-NEXT:     },
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "clang-module-deps": [],
+// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:       "command-line": [
+// CHECK-NEXT:         "-cc1"
+// CHECK:              "-emit-module"
+// CHECK:              "-I"
+// CHECK:              "[[PREFIX]]/b"
+// CHECK:              "-fmodule-name=mod"
+// CHECK:            ],
+// CHECK-NOT:        "context-hash": "[[HASH_MOD_A]]",
+// CHECK:            "file-deps": [
+// CHECK-NEXT:         "[[PREFIX]]/b/dep.h",
+// CHECK-NEXT:         "[[PREFIX]]/mod.h",
+// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT:       ],
+// CHECK-NEXT:       "name": "mod"
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
 // CHECK-NEXT:     {
 // CHECK-NEXT:       "clang-context-hash": "{{.*}}",
 // CHECK-NEXT:       "clang-module-deps": [
 // CHECK-NEXT:         {
-// CHECK-NEXT:           "context-hash": "[[HASH_MOD_B]]",
-// CHECK-NEXT:           "module-name": "mod"
+// CHECK-NOT:            "context-hash": "[[HASH_MOD_A]]",
+// CHECK:                "module-name": "mod"
 // CHECK-NEXT:         }
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "command-line": [