File tree 4 files changed +41
-0
lines changed
4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ See: https://arduino.github.io/arduino-cli/latest/sketch-specification/
20
20
package sketch
21
21
22
22
import (
23
+ "fmt"
24
+
23
25
"github.com/arduino/arduino-cli/arduino/globals"
24
26
"github.com/arduino/go-paths-helper"
25
27
)
@@ -31,6 +33,30 @@ func HasMainFileValidExtension(filePath *paths.Path) bool {
31
33
return hasMainFileValidExtension
32
34
}
33
35
36
+ // ContainsMainSketchFile checks whether the provided path contains a file with valid main sketch file extension.
37
+ func ContainsMainSketchFile (searchPath * paths.Path ) bool {
38
+ if searchPath .NotExist () {
39
+ panic (fmt .Sprintf ("Error: provided path %s does not exist." , searchPath ))
40
+ }
41
+ if searchPath .IsNotDir () {
42
+ panic (fmt .Sprintf ("Error: provided path %s is not a directory." , searchPath ))
43
+ }
44
+
45
+ directoryListing , err := searchPath .ReadDir ()
46
+ if err != nil {
47
+ panic (err )
48
+ }
49
+
50
+ directoryListing .FilterOutDirs ()
51
+ for _ , potentialHeaderFile := range directoryListing {
52
+ if HasMainFileValidExtension (potentialHeaderFile ) {
53
+ return true
54
+ }
55
+ }
56
+
57
+ return false
58
+ }
59
+
34
60
// HasSupportedExtension returns whether the file at the given path has any of the file extensions supported for source/header files of a sketch.
35
61
func HasSupportedExtension (filePath * paths.Path ) bool {
36
62
_ , hasAdditionalFileValidExtensions := globals .AdditionalFileValidExtensions [filePath .Ext ()]
Original file line number Diff line number Diff line change 16
16
package sketch
17
17
18
18
import (
19
+ "os"
19
20
"testing"
20
21
21
22
"github.com/arduino/go-paths-helper"
22
23
"github.com/stretchr/testify/assert"
23
24
)
24
25
26
+ var testDataPath * paths.Path
27
+
28
+ func init () {
29
+ workingDirectory , _ := os .Getwd ()
30
+ testDataPath = paths .New (workingDirectory , "testdata" )
31
+ }
32
+
25
33
func TestHasMainFileValidExtension (t * testing.T ) {
26
34
assert .True (t , HasMainFileValidExtension (paths .New ("/foo/bar.ino" )))
27
35
assert .False (t , HasMainFileValidExtension (paths .New ("/foo/bar.h" )))
28
36
}
29
37
38
+ func TestContainsMainSketchFile (t * testing.T ) {
39
+ assert .True (t , ContainsMainSketchFile (testDataPath .Join ("Valid" )))
40
+ assert .False (t , ContainsMainSketchFile (testDataPath .Join ("ContainsNoMainSketchFile" )))
41
+ }
42
+
30
43
func TestHasSupportedExtension (t * testing.T ) {
31
44
assert .True (t , HasSupportedExtension (paths .New ("/foo/bar.ino" )))
32
45
assert .True (t , HasSupportedExtension (paths .New ("/foo/bar.h" )))
Original file line number Diff line number Diff line change
1
+ void setup () {}
2
+ void loop () {}
You can’t perform that action at this time.
0 commit comments