-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip-changelog] Added flag to disable check for sketch foldername ma…
…tching sketch name (#1187) * Added flag to disable check for sketch foldername This is required to keep backward compatibility for arduino-builder that doesn't enforce this check. * Added missing source doc * Changed module sketch_test -> sketch * Fixed test * Return the detected sketch as part of the error
- Loading branch information
Showing
4 changed files
with
57 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,23 +13,22 @@ | |
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to [email protected]. | ||
|
||
package sketch_test | ||
package sketch | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/arduino/arduino-cli/arduino/sketch" | ||
"github.com/arduino/go-paths-helper" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewItem(t *testing.T) { | ||
sketchItem := filepath.Join("testdata", t.Name()+".ino") | ||
item := sketch.NewItem(sketchItem) | ||
item := NewItem(sketchItem) | ||
assert.Equal(t, sketchItem, item.Path) | ||
sourceBytes, err := item.GetSourceBytes() | ||
assert.Nil(t, err) | ||
|
@@ -38,20 +37,20 @@ func TestNewItem(t *testing.T) { | |
assert.Nil(t, err) | ||
assert.Equal(t, "#include <testlib.h>", sourceStr) | ||
|
||
item = sketch.NewItem("doesnt/exist") | ||
item = NewItem("doesnt/exist") | ||
sourceBytes, err = item.GetSourceBytes() | ||
assert.Nil(t, sourceBytes) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestSort(t *testing.T) { | ||
items := []*sketch.Item{ | ||
items := []*Item{ | ||
{"foo"}, | ||
{"baz"}, | ||
{"bar"}, | ||
} | ||
|
||
sort.Sort(sketch.ItemByPath(items)) | ||
sort.Sort(ItemByPath(items)) | ||
|
||
assert.Equal(t, "bar", items[0].Path) | ||
assert.Equal(t, "baz", items[1].Path) | ||
|
@@ -67,7 +66,7 @@ func TestNew(t *testing.T) { | |
otherFile, | ||
} | ||
|
||
sketch, err := sketch.New(sketchFolderPath, mainFilePath, "", allFilesPaths) | ||
sketch, err := New(sketchFolderPath, mainFilePath, "", allFilesPaths) | ||
assert.Nil(t, err) | ||
assert.Equal(t, mainFilePath, sketch.MainFile.Path) | ||
assert.Equal(t, sketchFolderPath, sketch.LocationPath) | ||
|
@@ -81,16 +80,20 @@ func TestNew(t *testing.T) { | |
func TestNewSketchCasingWrong(t *testing.T) { | ||
sketchPath := paths.New("testdata", "SketchCasingWrong") | ||
mainFilePath := paths.New("testadata", "sketchcasingwrong.ino").String() | ||
sketch, err := sketch.New(sketchPath.String(), mainFilePath, "", []string{mainFilePath}) | ||
sketch, err := New(sketchPath.String(), mainFilePath, "", []string{mainFilePath}) | ||
assert.Nil(t, sketch) | ||
assert.Error(t, err) | ||
assert.IsType(t, &InvalidSketchFoldernameError{}, err) | ||
e := err.(*InvalidSketchFoldernameError) | ||
assert.NotNil(t, e.Sketch) | ||
expectedError := fmt.Sprintf("no valid sketch found in %s: missing %s", sketchPath.String(), sketchPath.Join(sketchPath.Base()+".ino")) | ||
assert.EqualError(t, err, expectedError) | ||
} | ||
|
||
func TestNewSketchCasingCorrect(t *testing.T) { | ||
sketchPath := paths.New("testdata", "SketchCasingCorrect").String() | ||
mainFilePath := paths.New("testadata", "SketchCasingCorrect.ino").String() | ||
sketch, err := sketch.New(sketchPath, mainFilePath, "", []string{mainFilePath}) | ||
sketch, err := New(sketchPath, mainFilePath, "", []string{mainFilePath}) | ||
assert.NotNil(t, sketch) | ||
assert.NoError(t, err) | ||
assert.Equal(t, sketchPath, sketch.LocationPath) | ||
|
@@ -102,13 +105,13 @@ func TestNewSketchCasingCorrect(t *testing.T) { | |
|
||
func TestCheckSketchCasingWrong(t *testing.T) { | ||
sketchFolder := paths.New("testdata", "SketchCasingWrong") | ||
err := sketch.CheckSketchCasing(sketchFolder.String()) | ||
err := CheckSketchCasing(sketchFolder.String()) | ||
expectedError := fmt.Sprintf("no valid sketch found in %s: missing %s", sketchFolder, sketchFolder.Join(sketchFolder.Base()+".ino")) | ||
assert.EqualError(t, err, expectedError) | ||
} | ||
|
||
func TestCheckSketchCasingCorrect(t *testing.T) { | ||
sketchFolder := paths.New("testdata", "SketchCasingCorrect").String() | ||
err := sketch.CheckSketchCasing(sketchFolder) | ||
err := CheckSketchCasing(sketchFolder) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters