13
13
// Arduino software without disclosing the source code of your own applications.
14
14
// To purchase a commercial license, send an email to [email protected] .
15
15
16
- package sketch_test
16
+ package sketch
17
17
18
18
import (
19
19
"fmt"
20
20
"path/filepath"
21
21
"sort"
22
22
"testing"
23
23
24
- "github.com/arduino/arduino-cli/arduino/sketch"
25
24
"github.com/arduino/go-paths-helper"
26
25
"github.com/stretchr/testify/assert"
27
26
"github.com/stretchr/testify/require"
28
27
)
29
28
30
29
func TestNewItem (t * testing.T ) {
31
30
sketchItem := filepath .Join ("testdata" , t .Name ()+ ".ino" )
32
- item := sketch . NewItem (sketchItem )
31
+ item := NewItem (sketchItem )
33
32
assert .Equal (t , sketchItem , item .Path )
34
33
sourceBytes , err := item .GetSourceBytes ()
35
34
assert .Nil (t , err )
@@ -38,20 +37,20 @@ func TestNewItem(t *testing.T) {
38
37
assert .Nil (t , err )
39
38
assert .Equal (t , "#include <testlib.h>" , sourceStr )
40
39
41
- item = sketch . NewItem ("doesnt/exist" )
40
+ item = NewItem ("doesnt/exist" )
42
41
sourceBytes , err = item .GetSourceBytes ()
43
42
assert .Nil (t , sourceBytes )
44
43
assert .NotNil (t , err )
45
44
}
46
45
47
46
func TestSort (t * testing.T ) {
48
- items := []* sketch. Item {
47
+ items := []* Item {
49
48
{"foo" },
50
49
{"baz" },
51
50
{"bar" },
52
51
}
53
52
54
- sort .Sort (sketch . ItemByPath (items ))
53
+ sort .Sort (ItemByPath (items ))
55
54
56
55
assert .Equal (t , "bar" , items [0 ].Path )
57
56
assert .Equal (t , "baz" , items [1 ].Path )
@@ -67,7 +66,7 @@ func TestNew(t *testing.T) {
67
66
otherFile ,
68
67
}
69
68
70
- sketch , err := sketch . New (sketchFolderPath , mainFilePath , "" , allFilesPaths )
69
+ sketch , err := New (sketchFolderPath , mainFilePath , "" , allFilesPaths )
71
70
assert .Nil (t , err )
72
71
assert .Equal (t , mainFilePath , sketch .MainFile .Path )
73
72
assert .Equal (t , sketchFolderPath , sketch .LocationPath )
@@ -81,16 +80,20 @@ func TestNew(t *testing.T) {
81
80
func TestNewSketchCasingWrong (t * testing.T ) {
82
81
sketchPath := paths .New ("testdata" , "SketchCasingWrong" )
83
82
mainFilePath := paths .New ("testadata" , "sketchcasingwrong.ino" ).String ()
84
- sketch , err := sketch . New (sketchPath .String (), mainFilePath , "" , []string {mainFilePath })
83
+ sketch , err := New (sketchPath .String (), mainFilePath , "" , []string {mainFilePath })
85
84
assert .Nil (t , sketch )
85
+ assert .Error (t , err )
86
+ assert .IsType (t , & InvalidSketchFoldernameError {}, err )
87
+ e := err .(* InvalidSketchFoldernameError )
88
+ assert .NotNil (t , e .Sketch )
86
89
expectedError := fmt .Sprintf ("no valid sketch found in %s: missing %s" , sketchPath .String (), sketchPath .Join (sketchPath .Base ()+ ".ino" ))
87
90
assert .EqualError (t , err , expectedError )
88
91
}
89
92
90
93
func TestNewSketchCasingCorrect (t * testing.T ) {
91
94
sketchPath := paths .New ("testdata" , "SketchCasingCorrect" ).String ()
92
95
mainFilePath := paths .New ("testadata" , "SketchCasingCorrect.ino" ).String ()
93
- sketch , err := sketch . New (sketchPath , mainFilePath , "" , []string {mainFilePath })
96
+ sketch , err := New (sketchPath , mainFilePath , "" , []string {mainFilePath })
94
97
assert .NotNil (t , sketch )
95
98
assert .NoError (t , err )
96
99
assert .Equal (t , sketchPath , sketch .LocationPath )
@@ -102,13 +105,13 @@ func TestNewSketchCasingCorrect(t *testing.T) {
102
105
103
106
func TestCheckSketchCasingWrong (t * testing.T ) {
104
107
sketchFolder := paths .New ("testdata" , "SketchCasingWrong" )
105
- err := sketch . CheckSketchCasing (sketchFolder .String ())
108
+ err := CheckSketchCasing (sketchFolder .String ())
106
109
expectedError := fmt .Sprintf ("no valid sketch found in %s: missing %s" , sketchFolder , sketchFolder .Join (sketchFolder .Base ()+ ".ino" ))
107
110
assert .EqualError (t , err , expectedError )
108
111
}
109
112
110
113
func TestCheckSketchCasingCorrect (t * testing.T ) {
111
114
sketchFolder := paths .New ("testdata" , "SketchCasingCorrect" ).String ()
112
- err := sketch . CheckSketchCasing (sketchFolder )
115
+ err := CheckSketchCasing (sketchFolder )
113
116
require .NoError (t , err )
114
117
}
0 commit comments