Skip to content

Commit f1faeaa

Browse files
committed
make regexp more specific, add test
1 parent 78941c0 commit f1faeaa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
478478
}
479479

480480
// includeRegexp fixdoc
481-
var includeRegexp = regexp.MustCompile(`(?ms)[<"'](\S+)[">']`)
481+
var includeRegexp = regexp.MustCompile(`#include[ \t]*[<"](\S+)[">]`)
482482

483483
// IncludesFinderWithRegExp fixdoc
484484
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" +
81+
" 23 | #include \"Foobar.h\"" +
82+
" | ^~~~~~~~~~"
83+
84+
include := detector.IncludesFinderWithRegExp(output)
85+
86+
require.Equal(t, "Foobar.h", include)
87+
}

0 commit comments

Comments
 (0)