1313// Arduino software without disclosing the source code of your own applications.
1414// To purchase a commercial license, send an email to license@arduino.cc.
1515
16- package sketch_test
16+ package sketch
1717
1818import (
1919 "fmt"
2020 "path/filepath"
2121 "sort"
2222 "testing"
2323
24- "github.com/arduino/arduino-cli/arduino/sketch"
2524 "github.com/arduino/go-paths-helper"
2625 "github.com/stretchr/testify/assert"
2726 "github.com/stretchr/testify/require"
2827)
2928
3029func TestNewItem (t * testing.T ) {
3130 sketchItem := filepath .Join ("testdata" , t .Name ()+ ".ino" )
32- item := sketch . NewItem (sketchItem )
31+ item := NewItem (sketchItem )
3332 assert .Equal (t , sketchItem , item .Path )
3433 sourceBytes , err := item .GetSourceBytes ()
3534 assert .Nil (t , err )
@@ -38,20 +37,20 @@ func TestNewItem(t *testing.T) {
3837 assert .Nil (t , err )
3938 assert .Equal (t , "#include <testlib.h>" , sourceStr )
4039
41- item = sketch . NewItem ("doesnt/exist" )
40+ item = NewItem ("doesnt/exist" )
4241 sourceBytes , err = item .GetSourceBytes ()
4342 assert .Nil (t , sourceBytes )
4443 assert .NotNil (t , err )
4544}
4645
4746func TestSort (t * testing.T ) {
48- items := []* sketch. Item {
47+ items := []* Item {
4948 {"foo" },
5049 {"baz" },
5150 {"bar" },
5251 }
5352
54- sort .Sort (sketch . ItemByPath (items ))
53+ sort .Sort (ItemByPath (items ))
5554
5655 assert .Equal (t , "bar" , items [0 ].Path )
5756 assert .Equal (t , "baz" , items [1 ].Path )
@@ -67,7 +66,7 @@ func TestNew(t *testing.T) {
6766 otherFile ,
6867 }
6968
70- sketch , err := sketch . New (sketchFolderPath , mainFilePath , "" , allFilesPaths )
69+ sketch , err := New (sketchFolderPath , mainFilePath , "" , allFilesPaths )
7170 assert .Nil (t , err )
7271 assert .Equal (t , mainFilePath , sketch .MainFile .Path )
7372 assert .Equal (t , sketchFolderPath , sketch .LocationPath )
@@ -81,16 +80,20 @@ func TestNew(t *testing.T) {
8180func TestNewSketchCasingWrong (t * testing.T ) {
8281 sketchPath := paths .New ("testdata" , "SketchCasingWrong" )
8382 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 })
8584 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 )
8689 expectedError := fmt .Sprintf ("no valid sketch found in %s: missing %s" , sketchPath .String (), sketchPath .Join (sketchPath .Base ()+ ".ino" ))
8790 assert .EqualError (t , err , expectedError )
8891}
8992
9093func TestNewSketchCasingCorrect (t * testing.T ) {
9194 sketchPath := paths .New ("testdata" , "SketchCasingCorrect" ).String ()
9295 mainFilePath := paths .New ("testadata" , "SketchCasingCorrect.ino" ).String ()
93- sketch , err := sketch . New (sketchPath , mainFilePath , "" , []string {mainFilePath })
96+ sketch , err := New (sketchPath , mainFilePath , "" , []string {mainFilePath })
9497 assert .NotNil (t , sketch )
9598 assert .NoError (t , err )
9699 assert .Equal (t , sketchPath , sketch .LocationPath )
@@ -102,13 +105,13 @@ func TestNewSketchCasingCorrect(t *testing.T) {
102105
103106func TestCheckSketchCasingWrong (t * testing.T ) {
104107 sketchFolder := paths .New ("testdata" , "SketchCasingWrong" )
105- err := sketch . CheckSketchCasing (sketchFolder .String ())
108+ err := CheckSketchCasing (sketchFolder .String ())
106109 expectedError := fmt .Sprintf ("no valid sketch found in %s: missing %s" , sketchFolder , sketchFolder .Join (sketchFolder .Base ()+ ".ino" ))
107110 assert .EqualError (t , err , expectedError )
108111}
109112
110113func TestCheckSketchCasingCorrect (t * testing.T ) {
111114 sketchFolder := paths .New ("testdata" , "SketchCasingCorrect" ).String ()
112- err := sketch . CheckSketchCasing (sketchFolder )
115+ err := CheckSketchCasing (sketchFolder )
113116 require .NoError (t , err )
114117}
0 commit comments