Skip to content

Commit 63bfd5c

Browse files
dennisppaulcmaglie
andauthored
improved error messages parsing (#2782)
* improved regexp to also parse error messages with single quotes around header file name * make regexp more specific, add test * remove GH test failing escaped quotation marks * fix formatting * Use a more strict regexp / fix unit-test --------- Co-authored-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent 6d9c930 commit 63bfd5c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

internal/arduino/builder/internal/detector/detector.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
477477
return nil
478478
}
479479

480-
// includeRegexp fixdoc
481-
var includeRegexp = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
480+
var includeRegexp = regexp.MustCompile(`(?ms)^\s*[0-9 |]*\s*#[ \t]*include\s*[<"](\S+)[">]`)
482481

483482
// IncludesFinderWithRegExp fixdoc
484483
func IncludesFinderWithRegExp(source string) string {

internal/arduino/builder/internal/detector/detector_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,13 @@ func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) {
7575

7676
require.Equal(t, "register.h", include)
7777
}
78+
79+
func TestIncludesFinderWithRegExpPaddedIncludes5(t *testing.T) {
80+
output := "/some/path/sketch.ino:23:42: fatal error: 'Foobar.h' file not found\n" +
81+
" 23 | #include \"Foobar.h\"\n" +
82+
" | ^~~~~~~~~~\n"
83+
84+
include := detector.IncludesFinderWithRegExp(output)
85+
86+
require.Equal(t, "Foobar.h", include)
87+
}

0 commit comments

Comments
 (0)