From 1089015fcc3257dca9eac0b3319e242d95423973 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 4 Aug 2020 14:14:40 +0200 Subject: 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. --- pkg/csource/csource_test.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'pkg/csource/csource_test.go') 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]) } } } -- cgit mrf-deployment