Skip to content

Commit e910cbd

Browse files
Add test of a backslash in a file path on Linux and Mac OS X.
While I'm here, fix a typo in the name of json_formating.c and add `--` to its `3c` command lines.
1 parent 8255eab commit e910cbd

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

clang/test/3C/json_formating.c renamed to clang/test/3C/json_formatting.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: rm -rf %t*
22
// RUN: mkdir %t.alltypes && cd %t.alltypes
3-
// RUN: 3c -base-dir=%S -alltypes -dump-stats -dump-intermediate -debug-solver %s
3+
// RUN: 3c -base-dir=%S -alltypes -dump-stats -dump-intermediate -debug-solver %s --
44
// RUN: python -c "import json, glob; [json.load(open(f)) for f in glob.glob('*.json')]"
55
// RUN: mkdir %t.noalltypes && cd %t.noalltypes
6-
// RUN: 3c -base-dir=%S -dump-stats -dump-intermediate -debug-solver %s
6+
// RUN: 3c -base-dir=%S -dump-stats -dump-intermediate -debug-solver %s --
77
// RUN: python -c "import json, glob; [json.load(open(f)) for f in glob.glob('*.json')]"
88

99
// Testing that json files output for statistics logging are well formed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Regression test for a bug in which 3C didn't escape backslashes in file paths
2+
// in its JSON output
3+
// (https://github.com/correctcomputation/checkedc-clang/issues/619). On
4+
// Windows, file paths contain backslashes as the directory separator, so the
5+
// main json_formatting.c test would catch the bug. This test catches the bug on
6+
// Linux and Mac OS X by manually creating a file with a backslash in the name
7+
// (which is an ordinary filename character on these OSes).
8+
9+
// UNSUPPORTED: system-windows
10+
11+
// We reuse json_formatting.c to ensure that we test all the same code
12+
// constructs, but we `#include` it instead of running 3c on it directly because
13+
// some code used by 3c seems to be messing with backslashes in file names on
14+
// the command line. The `#include` seems to preserve the backslash. (This is an
15+
// unusual case, so it wouldn't be surprising if 3c's behavior changes at some
16+
// point and this test breaks and we have to redesign it.)
17+
18+
// RUN: rm -rf %t*
19+
20+
// RUN: mkdir %t.alltypes && cd %t.alltypes
21+
// RUN: cp %s .
22+
// RUN: cp %S/json_formatting.c 'json\_formatting.h'
23+
// RUN: 3c -alltypes -dump-stats -dump-intermediate -debug-solver -output-dir=out.checked json_formatting_backslash.c --
24+
// RUN: python -c "import json, glob; [json.load(open(f)) for f in glob.glob('*.json')]"
25+
26+
// RUN: mkdir %t.noalltypes && cd %t.noalltypes
27+
// RUN: cp %s .
28+
// RUN: cp %S/json_formatting.c 'json\_formatting.h'
29+
// RUN: 3c -dump-stats -dump-intermediate -debug-solver -output-dir=out.checked json_formatting_backslash.c --
30+
// RUN: python -c "import json, glob; [json.load(open(f)) for f in glob.glob('*.json')]"
31+
32+
// Even though this looks like a double-quoted string, the Checked C compiler
33+
// seems to require the backslash to _not_ be escaped. We choose `\_` because it
34+
// is not a valid escape sequence in a JSON string literal (see
35+
// https://www.json.org/).
36+
#include "json\_formatting.h"

0 commit comments

Comments
 (0)