diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-08-04 14:14:40 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-08-04 16:53:31 +0200 |
| commit | 1089015fcc3257dca9eac0b3319e242d95423973 (patch) | |
| tree | f14e38e4f45d5da9d42ecdc27b87eda3638fe07a /pkg/csource/csource_test.go | |
| parent | 5ed76afa814812edaeaff2ea7b3227c18d5de5a6 (diff) | |
executor: remove block comments
1. We don't generally use /* */ block comments,
few precedents we have are inconsistent with the rest of the code.
2. pkg/csource does not strip them from the resulting code.
Remove the cases we have and add a test to prevent new ones being added.
Diffstat (limited to 'pkg/csource/csource_test.go')
| -rw-r--r-- | pkg/csource/csource_test.go | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go index 152c732b8..a3a731a7c 100644 --- a/pkg/csource/csource_test.go +++ b/pkg/csource/csource_test.go @@ -186,24 +186,38 @@ func TestExecutorMacros(t *testing.T) { } func TestExecutorMistakes(t *testing.T) { - mistakes := map[string][]string{ - // We strip debug() calls from the resulting C source, - // this breaks the following pattern. Use {} around debug() to fix. - "\\)\n\\t*(debug|debug_dump_data)\\(": { - ` + mistakes := []struct { + pattern string + message string + tests []string + }{ + { + pattern: `\)\n\t*(debug|debug_dump_data)\(`, + message: "debug() calls are stripped from C reproducers, this code will break. Use {} around debug() to fix", + tests: []string{ + ` if (foo) debug("foo failed"); `, ` if (x + y) debug_dump_data(data, len); `, + }, + }, + { + // These are also not properly stripped by pkg/csource. + pattern: `/\*[^{]`, + message: "Don't use /* */ block comments. Use // line comments instead", + tests: []string{ + `/* C++ comment */`, + }, }, } - for pattern, tests := range mistakes { - re := regexp.MustCompile(pattern) - for _, test := range tests { + for _, mistake := range mistakes { + re := regexp.MustCompile(mistake.pattern) + for _, test := range mistake.tests { if !re.MatchString(test) { - t.Errorf("patter %q does not match test %q", pattern, test) + t.Errorf("patter %q does not match test %q", mistake.pattern, test) } } for _, match := range re.FindAllStringIndex(commonHeader, -1) { @@ -214,8 +228,7 @@ if (foo) for end != len(commonHeader) && commonHeader[end] != '\n' { end++ } - t.Errorf("pattern %q matches executor source:\n%v", - pattern, commonHeader[start:end]) + t.Errorf("%v:%v", mistake.message, commonHeader[start:end]) } } } |
