diff --git a/arduino/builder/sketch_test.go b/arduino/builder/sketch_test.go index 33a2f034cb0..3d090b3fd53 100644 --- a/arduino/builder/sketch_test.go +++ b/arduino/builder/sketch_test.go @@ -230,3 +230,17 @@ func TestCopyAdditionalFiles(t *testing.T) { info2, err := os.Stat(s2.AdditionalFiles[0].Path) require.Equal(t, info1.ModTime(), info2.ModTime()) } + +func TestLoadSketchCaseMismatch(t *testing.T) { + // pass the path to the sketch folder + sketchPath := filepath.Join("testdata", t.Name()) + mainFilePath := filepath.Join(sketchPath, t.Name()+".ino") + s, err := builder.SketchLoad(sketchPath, "") + require.Nil(t, s) + require.Error(t, err) + + // pass the path to the main file + s, err = builder.SketchLoad(mainFilePath, "") + require.Nil(t, s) + require.Error(t, err) +} diff --git a/legacy/builder/test/sketch1/sketch.ino b/arduino/builder/testdata/TestLoadSketchCaseMismatch/testloadsketchcasemismatch.ino similarity index 100% rename from legacy/builder/test/sketch1/sketch.ino rename to arduino/builder/testdata/TestLoadSketchCaseMismatch/testloadsketchcasemismatch.ino diff --git a/arduino/sketch/sketch.go b/arduino/sketch/sketch.go index 7069beca882..ae9455d7e96 100644 --- a/arduino/sketch/sketch.go +++ b/arduino/sketch/sketch.go @@ -22,6 +22,7 @@ import ( "strings" "github.com/arduino/arduino-cli/arduino/globals" + "github.com/arduino/go-paths-helper" "github.com/pkg/errors" ) @@ -116,6 +117,10 @@ func New(sketchFolderPath, mainFilePath, buildPath string, allFilesPaths []strin sort.Sort(ItemByPath(additionalFiles)) sort.Sort(ItemByPath(otherSketchFiles)) + if err := CheckSketchCasing(sketchFolderPath); err != nil { + return nil, err + } + return &Sketch{ MainFile: mainFile, LocationPath: sketchFolderPath, @@ -123,3 +128,32 @@ func New(sketchFolderPath, mainFilePath, buildPath string, allFilesPaths []strin AdditionalFiles: additionalFiles, }, nil } + +// CheckSketchCasing returns an error if the casing of the sketch folder and the main file are different. +// Correct: +// MySketch/MySketch.ino +// Wrong: +// MySketch/mysketch.ino +// mysketch/MySketch.ino +// +// This is mostly necessary to avoid errors on Mac OS X. +// For more info see: https://github.com/arduino/arduino-cli/issues/1174 +func CheckSketchCasing(sketchFolder string) error { + sketchPath := paths.New(sketchFolder) + files, err := sketchPath.ReadDir() + if err != nil { + return errors.Errorf("reading files: %v", err) + } + files.FilterOutDirs() + + sketchName := sketchPath.Base() + files.FilterPrefix(sketchName) + + if files.Len() == 0 { + sketchFolderPath := paths.New(sketchFolder) + sketchFile := sketchFolderPath.Join(sketchFolderPath.Base() + globals.MainFileValidExtension) + return errors.Errorf("no valid sketch found in %s: missing %s", sketchFolderPath, sketchFile) + } + + return nil +} diff --git a/arduino/sketch/sketch_test.go b/arduino/sketch/sketch_test.go index 3e213fecba8..b0fd05fe216 100644 --- a/arduino/sketch/sketch_test.go +++ b/arduino/sketch/sketch_test.go @@ -16,12 +16,15 @@ package sketch_test 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) { @@ -43,9 +46,9 @@ func TestNewItem(t *testing.T) { func TestSort(t *testing.T) { items := []*sketch.Item{ - &sketch.Item{"foo"}, - &sketch.Item{"baz"}, - &sketch.Item{"bar"}, + {"foo"}, + {"baz"}, + {"bar"}, } sort.Sort(sketch.ItemByPath(items)) @@ -71,3 +74,37 @@ func TestNew(t *testing.T) { assert.Len(t, sketch.OtherSketchFiles, 0) assert.Len(t, sketch.AdditionalFiles, 1) } + +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}) + assert.Nil(t, 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}) + assert.NotNil(t, sketch) + assert.NoError(t, err) + assert.Equal(t, sketchPath, sketch.LocationPath) + assert.Equal(t, mainFilePath, sketch.MainFile.Path) + assert.Len(t, sketch.OtherSketchFiles, 0) + assert.Len(t, sketch.AdditionalFiles, 0) +} + +func TestCheckSketchCasingWrong(t *testing.T) { + sketchFolder := paths.New("testdata", "SketchCasingWrong") + err := sketch.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) + require.NoError(t, err) +} diff --git a/legacy/builder/test/sketch_with_backup_files/sketch.ino b/arduino/sketch/testdata/SketchCasingCorrect/SketchCasingCorrect.ino similarity index 100% rename from legacy/builder/test/sketch_with_backup_files/sketch.ino rename to arduino/sketch/testdata/SketchCasingCorrect/SketchCasingCorrect.ino diff --git a/arduino/sketch/testdata/SketchCasingWrong/sketchcasingwrong.ino b/arduino/sketch/testdata/SketchCasingWrong/sketchcasingwrong.ino new file mode 100644 index 00000000000..0d5e0f5ceb9 --- /dev/null +++ b/arduino/sketch/testdata/SketchCasingWrong/sketchcasingwrong.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/arduino/sketches/sketches.go b/arduino/sketches/sketches.go index d219e936f62..bc15dfb9762 100644 --- a/arduino/sketches/sketches.go +++ b/arduino/sketches/sketches.go @@ -21,6 +21,7 @@ import ( "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/globals" + "github.com/arduino/arduino-cli/arduino/sketch" "github.com/arduino/go-paths-helper" "github.com/pkg/errors" ) @@ -70,19 +71,19 @@ func NewSketchFromPath(path *paths.Path) (*Sketch, error) { } } - if mainSketchFile == nil { + if mainSketchFile == nil || sketch.CheckSketchCasing(path.String()) != nil { sketchFile := path.Join(path.Base() + globals.MainFileValidExtension) return nil, errors.Errorf("no valid sketch found in %s: missing %s", path, sketchFile) } - sketch := &Sketch{ + s := &Sketch{ FullPath: path, MainFileExtension: mainSketchFile.Ext(), Name: path.Base(), Metadata: &Metadata{}, } - sketch.ImportMetadata() - return sketch, nil + s.ImportMetadata() + return s, nil } // ImportMetadata imports metadata into the sketch from a sketch.json file in the root diff --git a/arduino/sketches/sketches_test.go b/arduino/sketches/sketches_test.go index 49ea771e4fd..ad65df39c0b 100644 --- a/arduino/sketches/sketches_test.go +++ b/arduino/sketches/sketches_test.go @@ -109,3 +109,24 @@ func TestCheckForPdeFiles(t *testing.T) { require.Len(t, files, 1) require.Equal(t, sketchPath.Parent().Join("SketchMultipleMainFiles.pde"), files[0]) } + +func TestSketchLoadWithCasing(t *testing.T) { + sketchFolder := paths.New("testdata", "SketchCasingWrong") + + sketch, err := NewSketchFromPath(sketchFolder) + require.Nil(t, sketch) + + sketchFolderAbs, _ := sketchFolder.Abs() + sketchMainFileAbs := sketchFolderAbs.Join("SketchCasingWrong.ino") + expectedError := fmt.Sprintf("no valid sketch found in %s: missing %s", sketchFolderAbs, sketchMainFileAbs) + require.EqualError(t, err, expectedError) +} + +func TestSketchLoadingCorrectCasing(t *testing.T) { + sketchFolder := paths.New("testdata", "SketchCasingCorrect") + sketch, err := NewSketchFromPath(sketchFolder) + require.NotNil(t, sketch) + require.NoError(t, err) + require.Equal(t, sketch.Name, "SketchCasingCorrect") + require.True(t, sketch.FullPath.EquivalentTo(sketchFolder)) +} diff --git a/arduino/sketches/testdata/SketchCasingCorrect/SketchCasingCorrect.ino b/arduino/sketches/testdata/SketchCasingCorrect/SketchCasingCorrect.ino new file mode 100644 index 00000000000..0d5e0f5ceb9 --- /dev/null +++ b/arduino/sketches/testdata/SketchCasingCorrect/SketchCasingCorrect.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/arduino/sketches/testdata/SketchCasingWrong/sketchcasingwrong.ino b/arduino/sketches/testdata/SketchCasingWrong/sketchcasingwrong.ino new file mode 100644 index 00000000000..0d5e0f5ceb9 --- /dev/null +++ b/arduino/sketches/testdata/SketchCasingWrong/sketchcasingwrong.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/legacy/builder/test/sketch3/Baladuino.ino b/legacy/builder/test/Baladuino/Baladuino.ino similarity index 100% rename from legacy/builder/test/sketch3/Baladuino.ino rename to legacy/builder/test/Baladuino/Baladuino.ino diff --git a/legacy/builder/test/sketch3/Baladuino.preprocessed.txt b/legacy/builder/test/Baladuino/Baladuino.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch3/Baladuino.preprocessed.txt rename to legacy/builder/test/Baladuino/Baladuino.preprocessed.txt diff --git a/legacy/builder/test/sketch4/CharWithEscapedDoubleQuote.ino b/legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.ino similarity index 100% rename from legacy/builder/test/sketch4/CharWithEscapedDoubleQuote.ino rename to legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.ino diff --git a/legacy/builder/test/sketch4/CharWithEscapedDoubleQuote.preprocessed.txt b/legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch4/CharWithEscapedDoubleQuote.preprocessed.txt rename to legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.preprocessed.txt diff --git a/legacy/builder/test/sketch5/IncludeBetweenMultilineComment.ino b/legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.ino similarity index 100% rename from legacy/builder/test/sketch5/IncludeBetweenMultilineComment.ino rename to legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.ino diff --git a/legacy/builder/test/sketch5/IncludeBetweenMultilineComment.preprocessed.txt b/legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch5/IncludeBetweenMultilineComment.preprocessed.txt rename to legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.preprocessed.txt diff --git a/legacy/builder/test/sketch6/LineContinuations.ino b/legacy/builder/test/LineContinuations/LineContinuations.ino similarity index 100% rename from legacy/builder/test/sketch6/LineContinuations.ino rename to legacy/builder/test/LineContinuations/LineContinuations.ino diff --git a/legacy/builder/test/sketch6/LineContinuations.preprocessed.txt b/legacy/builder/test/LineContinuations/LineContinuations.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch6/LineContinuations.preprocessed.txt rename to legacy/builder/test/LineContinuations/LineContinuations.preprocessed.txt diff --git a/legacy/builder/test/sketch2/SketchWithIfDef.ino b/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.ino similarity index 100% rename from legacy/builder/test/sketch2/SketchWithIfDef.ino rename to legacy/builder/test/SketchWithIfDef/SketchWithIfDef.ino diff --git a/legacy/builder/test/sketch2/SketchWithIfDef.preprocessed.txt b/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch2/SketchWithIfDef.preprocessed.txt rename to legacy/builder/test/SketchWithIfDef/SketchWithIfDef.preprocessed.txt diff --git a/legacy/builder/test/sketch2/SketchWithIfDef.resolved.directives.txt b/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt similarity index 100% rename from legacy/builder/test/sketch2/SketchWithIfDef.resolved.directives.txt rename to legacy/builder/test/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt diff --git a/legacy/builder/test/sketch2/empty_1.h b/legacy/builder/test/SketchWithIfDef/empty_1.h similarity index 100% rename from legacy/builder/test/sketch2/empty_1.h rename to legacy/builder/test/SketchWithIfDef/empty_1.h diff --git a/legacy/builder/test/sketch2/empty_2.h b/legacy/builder/test/SketchWithIfDef/empty_2.h similarity index 100% rename from legacy/builder/test/sketch2/empty_2.h rename to legacy/builder/test/SketchWithIfDef/empty_2.h diff --git a/legacy/builder/test/sketch8/SketchWithStruct.ino b/legacy/builder/test/SketchWithStruct/SketchWithStruct.ino similarity index 100% rename from legacy/builder/test/sketch8/SketchWithStruct.ino rename to legacy/builder/test/SketchWithStruct/SketchWithStruct.ino diff --git a/legacy/builder/test/sketch8/SketchWithStruct.preprocessed.txt b/legacy/builder/test/SketchWithStruct/SketchWithStruct.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch8/SketchWithStruct.preprocessed.txt rename to legacy/builder/test/SketchWithStruct/SketchWithStruct.preprocessed.txt diff --git a/legacy/builder/test/sketch7/StringWithComment.ino b/legacy/builder/test/StringWithComment/StringWithComment.ino similarity index 100% rename from legacy/builder/test/sketch7/StringWithComment.ino rename to legacy/builder/test/StringWithComment/StringWithComment.ino diff --git a/legacy/builder/test/sketch7/StringWithComment.preprocessed.txt b/legacy/builder/test/StringWithComment/StringWithComment.preprocessed.txt similarity index 100% rename from legacy/builder/test/sketch7/StringWithComment.preprocessed.txt rename to legacy/builder/test/StringWithComment/StringWithComment.preprocessed.txt diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index 351b3a6c8d6..d44aa8439c1 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -46,7 +46,7 @@ func prepareBuilderTestContext(t *testing.T, sketchPath *paths.Path, fqbn string func TestBuilderEmptySketch(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch.ino"), "arduino:avr:uno") + ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno") ctx.DebugLevel = 10 buildPath := SetupBuildPath(t, ctx) @@ -63,13 +63,13 @@ func TestBuilderEmptySketch(t *testing.T) { exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "sketch.ino.cpp.o").ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_SKETCH, "sketch1.ino.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join("sketch.ino.elf").ExistCheck() + exist, err = buildPath.Join("sketch1.ino.elf").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join("sketch.ino.hex").ExistCheck() + exist, err = buildPath.Join("sketch1.ino.hex").ExistCheck() NoError(t, err) require.True(t, exist) } @@ -277,7 +277,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) { func TestBuilderSketchWithBackup(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - ctx := prepareBuilderTestContext(t, paths.New("sketch_with_backup_files", "sketch.ino"), "arduino:avr:uno") + ctx := prepareBuilderTestContext(t, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino"), "arduino:avr:uno") ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff")) ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff")) @@ -293,7 +293,7 @@ func TestBuilderSketchWithBackup(t *testing.T) { func TestBuilderSketchWithOldLib(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - ctx := prepareBuilderTestContext(t, paths.New("sketch_with_old_lib", "sketch.ino"), "arduino:avr:uno") + ctx := prepareBuilderTestContext(t, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino"), "arduino:avr:uno") buildPath := SetupBuildPath(t, ctx) defer buildPath.RemoveAll() @@ -344,7 +344,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin func TestBuilderWithBuildPathInSketchDir(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch.ino"), "arduino:avr:uno") + ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno") var err error ctx.BuildPath, err = paths.New("sketch1", "build").Abs() @@ -365,7 +365,7 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) { func TestBuilderCacheCoreAFile(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch.ino"), "arduino:avr:uno") + ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno") SetupBuildPath(t, ctx) defer ctx.BuildPath.RemoveAll() diff --git a/legacy/builder/test/ctags_runner_test.go b/legacy/builder/test/ctags_runner_test.go index 3994958b694..c783ef5b8ba 100644 --- a/legacy/builder/test/ctags_runner_test.go +++ b/legacy/builder/test/ctags_runner_test.go @@ -79,7 +79,7 @@ func TestCTagsRunner(t *testing.T) { func TestCTagsRunnerSketchWithClass(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := Abs(t, paths.New("sketch_with_class", "sketch.ino")) + sketchLocation := Abs(t, paths.New("sketch_with_class", "sketch_with_class.ino")) ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), @@ -127,7 +127,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { func TestCTagsRunnerSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := Abs(t, paths.New("sketch_with_typename", "sketch.ino")) + sketchLocation := Abs(t, paths.New("sketch_with_typename", "sketch_with_typename.ino")) ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), @@ -174,7 +174,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { func TestCTagsRunnerSketchWithNamespace(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := Abs(t, paths.New("sketch_with_namespace", "sketch.ino")) + sketchLocation := Abs(t, paths.New("sketch_with_namespace", "sketch_with_namespace.ino")) ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), @@ -220,7 +220,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { func TestCTagsRunnerSketchWithTemplates(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := Abs(t, paths.New("sketch_with_templates_and_shift", "template_and_shift.cpp")) + sketchLocation := Abs(t, paths.New("sketch_with_templates_and_shift", "sketch_with_templates_and_shift.cpp")) ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), diff --git a/legacy/builder/test/eol_processing/sketch.ino b/legacy/builder/test/eol_processing/eol_processing.ino similarity index 100% rename from legacy/builder/test/eol_processing/sketch.ino rename to legacy/builder/test/eol_processing/eol_processing.ino diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go index 30525723edf..c9300b28e78 100644 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ b/legacy/builder/test/includes_to_include_folders_test.go @@ -70,7 +70,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch2", "SketchWithIfDef.ino"), + SketchLocation: paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -105,7 +105,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch9", "sketch.ino"), + SketchLocation: paths.New("sketch9", "sketch9.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -143,7 +143,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch10", "sketch.ino"), + SketchLocation: paths.New("sketch10", "sketch10.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, diff --git a/legacy/builder/test/load_vid_pid_specific_properties_test.go b/legacy/builder/test/load_vid_pid_specific_properties_test.go index 41da45ec410..f3d1be3b43e 100644 --- a/legacy/builder/test/load_vid_pid_specific_properties_test.go +++ b/legacy/builder/test/load_vid_pid_specific_properties_test.go @@ -31,7 +31,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:micro"), ArduinoAPIVersion: "10600", } @@ -61,7 +61,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:micro"), ArduinoAPIVersion: "10600", } diff --git a/legacy/builder/test/merge_sketch_with_bootloader_test.go b/legacy/builder/test/merge_sketch_with_bootloader_test.go index 68441b5c1c6..ee7c59893a7 100644 --- a/legacy/builder/test/merge_sketch_with_bootloader_test.go +++ b/legacy/builder/test/merge_sketch_with_bootloader_test.go @@ -36,7 +36,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", } @@ -77,7 +77,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { :0C01B000F1F30E940000FBCFF894FFCF99 :00000001FF ` - err = buildPath.Join("sketch", "sketch.ino.hex").WriteFile([]byte(fakeSketchHex)) + err = buildPath.Join("sketch", "sketch1.ino.hex").WriteFile([]byte(fakeSketchHex)) NoError(t, err) commands := []types.Command{ @@ -90,7 +90,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { NoError(t, err) } - bytes, err := buildPath.Join("sketch", "sketch.ino.with_bootloader.hex").ReadFile() + bytes, err := buildPath.Join("sketch", "sketch1.ino.with_bootloader.hex").ReadFile() NoError(t, err) mergedSketchHex := string(bytes) @@ -106,7 +106,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", } @@ -147,7 +147,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { :0C01B000F1F30E940000FBCFF894FFCF99 :00000001FF ` - err = buildPath.Join("sketch.ino.hex").WriteFile([]byte(fakeSketchHex)) + err = buildPath.Join("sketch1.ino.hex").WriteFile([]byte(fakeSketchHex)) NoError(t, err) commands := []types.Command{ @@ -160,7 +160,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { NoError(t, err) } - bytes, err := buildPath.Join("sketch.ino.with_bootloader.hex").ReadFile() + bytes, err := buildPath.Join("sketch1.ino.with_bootloader.hex").ReadFile() NoError(t, err) mergedSketchHex := string(bytes) @@ -177,7 +177,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", } @@ -215,7 +215,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "my_avr_platform:avr:mymega:cpu=atmega2560"), ArduinoAPIVersion: "10600", } @@ -256,7 +256,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { :0C01B000F1F30E940000FBCFF894FFCF99 :00000001FF ` - err = buildPath.Join("sketch", "sketch.ino.hex").WriteFile([]byte(fakeSketchHex)) + err = buildPath.Join("sketch", "sketch1.ino.hex").WriteFile([]byte(fakeSketchHex)) NoError(t, err) commands := []types.Command{ @@ -269,7 +269,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { NoError(t, err) } - bytes, err := buildPath.Join("sketch", "sketch.ino.with_bootloader.hex").ReadFile() + bytes, err := buildPath.Join("sketch", "sketch1.ino.with_bootloader.hex").ReadFile() NoError(t, err) mergedSketchHex := string(bytes) diff --git a/legacy/builder/test/prototypes_adder_test.go b/legacy/builder/test/prototypes_adder_test.go index f93b928f9e2..811ae91508c 100644 --- a/legacy/builder/test/prototypes_adder_test.go +++ b/legacy/builder/test/prototypes_adder_test.go @@ -81,7 +81,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch2", "SketchWithIfDef.ino"), + SketchLocation: paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -109,7 +109,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithIfDef", "SketchWithIfDef.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -121,7 +121,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch3", "Baladuino.ino"), + SketchLocation: paths.New("Baladuino", "Baladuino.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -149,7 +149,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("Baladuino", "Baladuino.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -161,7 +161,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch4", "CharWithEscapedDoubleQuote.ino"), + SketchLocation: paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -189,7 +189,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -201,7 +201,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch5", "IncludeBetweenMultilineComment.ino"), + SketchLocation: paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino"), FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"), ArduinoAPIVersion: "10600", Verbose: true, @@ -229,7 +229,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -241,7 +241,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch6", "/LineContinuations.ino"), + SketchLocation: paths.New("LineContinuations", "LineContinuations.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -269,7 +269,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("LineContinuations", "LineContinuations.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -281,7 +281,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch7", "StringWithComment.ino"), + SketchLocation: paths.New("StringWithComment", "StringWithComment.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -309,7 +309,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("StringWithComment", "StringWithComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -321,7 +321,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch8", "SketchWithStruct.ino"), + SketchLocation: paths.New("SketchWithStruct", "SketchWithStruct.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -349,7 +349,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithStruct", "SketchWithStruct.preprocessed.txt"), ctx) obtained := strings.Replace(ctx.Source, "\r\n", "\n", -1) // ctags based preprocessing removes the space after "dostuff", but this is still OK // TODO: remove this exception when moving to a more powerful parser @@ -407,7 +407,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_no_functions_two_files", "main.ino") + sketchLocation := paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -415,7 +415,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch_no_functions_two_files", "main.ino"), + SketchLocation: paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -455,7 +455,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("sketch_no_functions", "main.ino"), + SketchLocation: paths.New("sketch_no_functions", "sketch_no_functions.ino"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), ArduinoAPIVersion: "10600", Verbose: true, @@ -464,7 +464,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { buildPath := SetupBuildPath(t, ctx) defer buildPath.RemoveAll() - sketchLocation := paths.New("sketch_no_functions", "main.ino") + sketchLocation := paths.New("sketch_no_functions", "sketch_no_functions.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) commands := []types.Command{ @@ -493,7 +493,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_default_args", "sketch.ino") + sketchLocation := paths.New("sketch_with_default_args", "sketch_with_default_args.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -536,7 +536,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_inline_function", "sketch.ino") + sketchLocation := paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -590,7 +590,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_function_signature_inside_ifdef", "sketch.ino") + sketchLocation := paths.New("sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -633,7 +633,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_usbcon", "sketch.ino") + sketchLocation := paths.New("sketch_with_usbcon", "sketch_with_usbcon.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -676,7 +676,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { func TestPrototypesAdderSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_typename", "sketch.ino") + sketchLocation := paths.New("sketch_with_typename", "sketch_with_typename.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -724,7 +724,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_ifdef", "sketch.ino") + sketchLocation := paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -770,7 +770,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_ifdef", "sketch.ino") + sketchLocation := paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -816,7 +816,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { func TestPrototypesAdderSketchWithConst(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - sketchLocation := paths.New("sketch_with_const", "sketch.ino") + sketchLocation := paths.New("sketch_with_const", "sketch_with_const.ino") quotedSketchLocation := utils.QuoteCppPath(Abs(t, sketchLocation)) ctx := &types.Context{ @@ -864,7 +864,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - SketchLocation: paths.New("eol_processing", "sketch.ino"), + SketchLocation: paths.New("eol_processing", "eol_processing.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", Verbose: true, diff --git a/legacy/builder/test/setup_build_properties_test.go b/legacy/builder/test/setup_build_properties_test.go index 43d2da09a94..995d7a42747 100644 --- a/legacy/builder/test/setup_build_properties_test.go +++ b/legacy/builder/test/setup_build_properties_test.go @@ -31,7 +31,7 @@ func TestSetupBuildProperties(t *testing.T) { ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", } @@ -97,7 +97,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "arduino:avr:uno"), ArduinoAPIVersion: "10600", @@ -138,7 +138,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), ArduinoAPIVersion: "10600", } @@ -176,7 +176,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi ctx := &types.Context{ HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"), BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - SketchLocation: paths.New("sketch1", "sketch.ino"), + SketchLocation: paths.New("sketch1", "sketch1.ino"), FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), ArduinoAPIVersion: "10600", } diff --git a/legacy/builder/test/sketch1/sketch1.ino b/legacy/builder/test/sketch1/sketch1.ino new file mode 100644 index 00000000000..0d5e0f5ceb9 --- /dev/null +++ b/legacy/builder/test/sketch1/sketch1.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/legacy/builder/test/sketch10/sketch.ino b/legacy/builder/test/sketch10/sketch10.ino similarity index 100% rename from legacy/builder/test/sketch10/sketch.ino rename to legacy/builder/test/sketch10/sketch10.ino diff --git a/legacy/builder/test/sketch9/sketch.ino b/legacy/builder/test/sketch9/sketch9.ino similarity index 100% rename from legacy/builder/test/sketch9/sketch.ino rename to legacy/builder/test/sketch9/sketch9.ino diff --git a/legacy/builder/test/sketch11/sketch_fastleds.ino b/legacy/builder/test/sketch_fastleds/sketch_fastleds.ino similarity index 100% rename from legacy/builder/test/sketch11/sketch_fastleds.ino rename to legacy/builder/test/sketch_fastleds/sketch_fastleds.ino diff --git a/legacy/builder/test/sketch_no_functions/main.ino b/legacy/builder/test/sketch_no_functions/sketch_no_functions.ino similarity index 100% rename from legacy/builder/test/sketch_no_functions/main.ino rename to legacy/builder/test/sketch_no_functions/sketch_no_functions.ino diff --git a/legacy/builder/test/sketch_no_functions_two_files/main.ino b/legacy/builder/test/sketch_no_functions_two_files/sketch_no_functions_two_files.ino similarity index 100% rename from legacy/builder/test/sketch_no_functions_two_files/main.ino rename to legacy/builder/test/sketch_no_functions_two_files/sketch_no_functions_two_files.ino diff --git a/legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch.ino b/legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch_that_checks_if_SPI_has_transactions.ino similarity index 100% rename from legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch.ino rename to legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch_that_checks_if_SPI_has_transactions.ino diff --git a/legacy/builder/test/sketch_with_backup_files/backup/sketch.ino b/legacy/builder/test/sketch_with_backup_files/backup/sketch_with_backup_files.ino similarity index 100% rename from legacy/builder/test/sketch_with_backup_files/backup/sketch.ino rename to legacy/builder/test/sketch_with_backup_files/backup/sketch_with_backup_files.ino diff --git a/legacy/builder/test/sketch_with_backup_files/sketch_with_backup_files.ino b/legacy/builder/test/sketch_with_backup_files/sketch_with_backup_files.ino new file mode 100644 index 00000000000..0d5e0f5ceb9 --- /dev/null +++ b/legacy/builder/test/sketch_with_backup_files/sketch_with_backup_files.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/legacy/builder/test/sketch_with_class/sketch.ino b/legacy/builder/test/sketch_with_class/sketch_with_class.ino similarity index 100% rename from legacy/builder/test/sketch_with_class/sketch.ino rename to legacy/builder/test/sketch_with_class/sketch_with_class.ino diff --git a/legacy/builder/test/sketch_with_const/sketch.ino b/legacy/builder/test/sketch_with_const/sketch_with_const.ino similarity index 100% rename from legacy/builder/test/sketch_with_const/sketch.ino rename to legacy/builder/test/sketch_with_const/sketch_with_const.ino diff --git a/legacy/builder/test/sketch_with_default_args/sketch.ino b/legacy/builder/test/sketch_with_default_args/sketch_with_default_args.ino similarity index 100% rename from legacy/builder/test/sketch_with_default_args/sketch.ino rename to legacy/builder/test/sketch_with_default_args/sketch_with_default_args.ino diff --git a/legacy/builder/test/sketch_with_dependend_libraries/sketch.ino b/legacy/builder/test/sketch_with_dependend_libraries/sketch_with_dependend_libraries.ino similarity index 100% rename from legacy/builder/test/sketch_with_dependend_libraries/sketch.ino rename to legacy/builder/test/sketch_with_dependend_libraries/sketch_with_dependend_libraries.ino diff --git a/legacy/builder/test/sketch_with_function_pointer/sketch.ino b/legacy/builder/test/sketch_with_function_pointer/sketch_with_function_pointer.ino similarity index 100% rename from legacy/builder/test/sketch_with_function_pointer/sketch.ino rename to legacy/builder/test/sketch_with_function_pointer/sketch_with_function_pointer.ino diff --git a/legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch.ino b/legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch_with_function_signature_inside_ifdef.ino similarity index 100% rename from legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch.ino rename to legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch_with_function_signature_inside_ifdef.ino diff --git a/legacy/builder/test/sketch_with_ifdef/sketch.ino b/legacy/builder/test/sketch_with_ifdef/sketch_with_ifdef.ino similarity index 100% rename from legacy/builder/test/sketch_with_ifdef/sketch.ino rename to legacy/builder/test/sketch_with_ifdef/sketch_with_ifdef.ino diff --git a/legacy/builder/test/sketch_with_inline_function/sketch.ino b/legacy/builder/test/sketch_with_inline_function/sketch_with_inline_function.ino similarity index 100% rename from legacy/builder/test/sketch_with_inline_function/sketch.ino rename to legacy/builder/test/sketch_with_inline_function/sketch_with_inline_function.ino diff --git a/legacy/builder/test/sketch_with_macosx_garbage/sketch.ino b/legacy/builder/test/sketch_with_macosx_garbage/sketch_with_macosx_garbage.ino similarity index 100% rename from legacy/builder/test/sketch_with_macosx_garbage/sketch.ino rename to legacy/builder/test/sketch_with_macosx_garbage/sketch_with_macosx_garbage.ino diff --git a/legacy/builder/test/sketch_with_namespace/sketch.ino b/legacy/builder/test/sketch_with_namespace/sketch_with_namespace.ino similarity index 100% rename from legacy/builder/test/sketch_with_namespace/sketch.ino rename to legacy/builder/test/sketch_with_namespace/sketch_with_namespace.ino diff --git a/legacy/builder/test/sketch_with_old_lib/sketch.ino b/legacy/builder/test/sketch_with_old_lib/sketch_with_old_lib.ino similarity index 100% rename from legacy/builder/test/sketch_with_old_lib/sketch.ino rename to legacy/builder/test/sketch_with_old_lib/sketch_with_old_lib.ino diff --git a/legacy/builder/test/sketch_with_templates_and_shift/template_and_shift.cpp b/legacy/builder/test/sketch_with_templates_and_shift/sketch_with_templates_and_shift.cpp similarity index 100% rename from legacy/builder/test/sketch_with_templates_and_shift/template_and_shift.cpp rename to legacy/builder/test/sketch_with_templates_and_shift/sketch_with_templates_and_shift.cpp diff --git a/legacy/builder/test/sketch_with_typename/sketch.ino b/legacy/builder/test/sketch_with_typename/sketch_with_typename.ino similarity index 100% rename from legacy/builder/test/sketch_with_typename/sketch.ino rename to legacy/builder/test/sketch_with_typename/sketch_with_typename.ino diff --git a/legacy/builder/test/sketch_with_usbcon/sketch.ino b/legacy/builder/test/sketch_with_usbcon/sketch_with_usbcon.ino similarity index 100% rename from legacy/builder/test/sketch_with_usbcon/sketch.ino rename to legacy/builder/test/sketch_with_usbcon/sketch_with_usbcon.ino diff --git a/legacy/builder/test/try_build_of_problematic_sketch_test.go b/legacy/builder/test/try_build_of_problematic_sketch_test.go index f23fe0d3e79..702ed136af6 100644 --- a/legacy/builder/test/try_build_of_problematic_sketch_test.go +++ b/legacy/builder/test/try_build_of_problematic_sketch_test.go @@ -26,27 +26,27 @@ import ( ) func TestTryBuild001(t *testing.T) { - tryBuild(t, "sketch_with_inline_function", "sketch.ino") + tryBuild(t, "sketch_with_inline_function", "sketch_with_inline_function.ino") } func TestTryBuild002(t *testing.T) { - tryBuild(t, "sketch_with_function_signature_inside_ifdef", "sketch.ino") + tryBuild(t, "sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino") } func TestTryBuild003(t *testing.T) { - tryPreprocess(t, "sketch_no_functions", "main.ino") + tryPreprocess(t, "sketch_no_functions", "sketch_no_functions.ino") } func TestTryBuild004(t *testing.T) { - tryBuild(t, "sketch_with_const", "sketch.ino") + tryBuild(t, "sketch_with_const", "sketch_with_const.ino") } func TestTryBuild005(t *testing.T) { - tryBuild(t, "sketch_with_old_lib", "sketch.ino") + tryBuild(t, "sketch_with_old_lib", "sketch_with_old_lib.ino") } func TestTryBuild006(t *testing.T) { - tryBuild(t, "sketch_with_macosx_garbage", "sketch.ino") + tryBuild(t, "sketch_with_macosx_garbage", "sketch_with_macosx_garbage.ino") } func TestTryBuild007(t *testing.T) { @@ -59,27 +59,27 @@ func TestTryBuild007(t *testing.T) { //} func TestTryBuild009(t *testing.T) { - tryBuild(t, "sketch_with_usbcon", "sketch.ino") + tryBuild(t, "sketch_with_usbcon", "sketch_with_usbcon.ino") } func TestTryBuild010(t *testing.T) { - tryBuild(t, "sketch_with_namespace", "sketch.ino") + tryBuild(t, "sketch_with_namespace", "sketch_with_namespace.ino") } func TestTryBuild011(t *testing.T) { - tryBuild(t, "sketch_with_inline_function", "sketch.ino") + tryBuild(t, "sketch_with_inline_function", "sketch_with_inline_function.ino") } func TestTryBuild012(t *testing.T) { - tryBuild(t, "sketch_with_default_args", "sketch.ino") + tryBuild(t, "sketch_with_default_args", "sketch_with_default_args.ino") } func TestTryBuild013(t *testing.T) { - tryBuild(t, "sketch_with_class", "sketch.ino") + tryBuild(t, "sketch_with_class", "sketch_with_class.ino") } func TestTryBuild014(t *testing.T) { - tryBuild(t, "sketch_with_backup_files", "sketch.ino") + tryBuild(t, "sketch_with_backup_files", "sketch_with_backup_files.ino") } func TestTryBuild015(t *testing.T) { @@ -92,25 +92,25 @@ func TestTryBuild015(t *testing.T) { //} func TestTryBuild017(t *testing.T) { - tryPreprocess(t, "sketch_no_functions_two_files", "main.ino") + tryPreprocess(t, "sketch_no_functions_two_files", "sketch_no_functions_two_files.ino") } func TestTryBuild018(t *testing.T) { - tryBuild(t, "sketch_that_checks_if_SPI_has_transactions", "sketch.ino") + tryBuild(t, "sketch_that_checks_if_SPI_has_transactions", "sketch_that_checks_if_SPI_has_transactions.ino") } func TestTryBuild019(t *testing.T) { - tryBuild(t, "sketch_with_ifdef", "sketch.ino") + tryBuild(t, "sketch_with_ifdef", "sketch_with_ifdef.ino") } func TestTryBuild020(t *testing.T) { ctx := makeDefaultContext(t) ctx.OtherLibrariesDirs = paths.NewPathList("dependent_libraries", "libraries") - tryPreprocessWithContext(t, ctx, "sketch_with_dependend_libraries", "sketch.ino") + tryPreprocessWithContext(t, ctx, "sketch_with_dependend_libraries", "sketch_with_dependend_libraries.ino") } func TestTryBuild021(t *testing.T) { - tryBuild(t, "sketch_with_function_pointer", "sketch.ino") + tryBuild(t, "sketch_with_function_pointer", "sketch_with_function_pointer.ino") } func TestTryBuild022(t *testing.T) { @@ -120,11 +120,11 @@ func TestTryBuild022(t *testing.T) { } func TestTryBuild023(t *testing.T) { - tryBuild(t, "sketch1", "sketch.ino") + tryBuild(t, "sketch1", "sketch1.ino") } func TestTryBuild024(t *testing.T) { - tryBuild(t, "sketch2", "SketchWithIfDef.ino") + tryBuild(t, "SketchWithIfDef", "SketchWithIfDef.ino") } // The library for this sketch is missing @@ -133,31 +133,31 @@ func TestTryBuild024(t *testing.T) { //} func TestTryBuild026(t *testing.T) { - tryBuild(t, "sketch4", "CharWithEscapedDoubleQuote.ino") + tryBuild(t, "CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino") } func TestTryBuild027(t *testing.T) { - tryBuild(t, "sketch5", "IncludeBetweenMultilineComment.ino") + tryBuild(t, "IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino") } func TestTryBuild028(t *testing.T) { - tryBuild(t, "sketch6", "LineContinuations.ino") + tryBuild(t, "LineContinuations", "LineContinuations.ino") } func TestTryBuild029(t *testing.T) { - tryBuild(t, "sketch7", "StringWithComment.ino") + tryBuild(t, "StringWithComment", "StringWithComment.ino") } func TestTryBuild030(t *testing.T) { - tryBuild(t, "sketch8", "SketchWithStruct.ino") + tryBuild(t, "SketchWithStruct", "SketchWithStruct.ino") } func TestTryBuild031(t *testing.T) { - tryBuild(t, "sketch9", "sketch.ino") + tryBuild(t, "sketch9", "sketch9.ino") } func TestTryBuild032(t *testing.T) { - tryBuild(t, "sketch10", "sketch.ino") + tryBuild(t, "sketch10", "sketch10.ino") } func TestTryBuild033(t *testing.T) { @@ -175,7 +175,7 @@ func TestTryBuild035(t *testing.T) { func TestTryBuild036(t *testing.T) { ctx := makeDefaultContext(t) ctx.FQBN = parseFQBN(t, "arduino:samd:arduino_zero_native") - tryBuildWithContext(t, ctx, "sketch11", "sketch_fastleds.ino") + tryBuildWithContext(t, ctx, "sketch_fastleds", "sketch_fastleds.ino") } func TestTryBuild037(t *testing.T) { diff --git a/test/test_compile.py b/test/test_compile.py index aee5b0c8a1d..9fe751eea54 100644 --- a/test/test_compile.py +++ b/test/test_compile.py @@ -695,3 +695,34 @@ def test_compile_sketch_with_multiple_main_files(run_command, data_dir): res = run_command(f"compile --clean -b {fqbn} {sketch_pde_file}") assert res.failed assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr + + +def test_compile_sketch_case_mismatch_fails(run_command, data_dir): + # Init the environment explicitly + assert run_command("update") + + # Install core to compile + assert run_command("core install arduino:avr@1.8.3") + + sketch_name = "CompileSketchCaseMismatch" + sketch_path = Path(data_dir, sketch_name) + fqbn = "arduino:avr:uno" + + assert run_command(f"sketch new {sketch_path}") + + # Rename main .ino file so casing is different from sketch name + sketch_main_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino") + + # Verifies compilation fails when: + # * Compiling with sketch path + res = run_command(f"compile --clean -b {fqbn} {sketch_path}") + assert res.failed + assert "Error during build: opening sketch: no valid sketch found" in res.stderr + # * Compiling with sketch main file + res = run_command(f"compile --clean -b {fqbn} {sketch_main_file}") + assert res.failed + assert "Error during build: opening sketch: no valid sketch found" in res.stderr + # * Compiling in sketch path + res = run_command(f"compile --clean -b {fqbn}", custom_working_dir=sketch_path) + assert res.failed + assert "Error during build: opening sketch: no valid sketch found" in res.stderr diff --git a/test/test_lib.py b/test/test_lib.py index f6c293e450b..034ae172c3c 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -668,3 +668,38 @@ def test_lib_examples_with_pde_file(run_command, data_dir): assert str(Path(data_dir, "libraries", "Encoder", "examples", "NoInterrupts")) in examples assert str(Path(data_dir, "libraries", "Encoder", "examples", "SpeedTest")) in examples assert str(Path(data_dir, "libraries", "Encoder", "examples", "TwoKnobs")) in examples + + +def test_lib_examples_with_case_mismatch(run_command, data_dir): + assert run_command("update") + + assert run_command("lib install WiFiManager@2.0.3-alpha") + + res = run_command("lib examples WiFiManager --format json") + assert res.ok + data = json.loads(res.stdout) + assert len(data) == 1 + examples = data[0]["examples"] + + assert len(examples) == 14 + + examples_path = Path(data_dir, "libraries", "WiFiManager", "examples") + # Verifies sketches with correct casing are listed + assert str(examples_path / "Advanced") in examples + assert str(examples_path / "AutoConnect" / "AutoConnectWithFeedbackLED") in examples + assert str(examples_path / "AutoConnect" / "AutoConnectWithFSParameters") in examples + assert str(examples_path / "AutoConnect" / "AutoConnectWithFSParametersAndCustomIP") in examples + assert str(examples_path / "Basic") in examples + assert str(examples_path / "DEV" / "OnDemandConfigPortal") in examples + assert str(examples_path / "NonBlocking" / "AutoConnectNonBlocking") in examples + assert str(examples_path / "NonBlocking" / "AutoConnectNonBlockingwParams") in examples + assert str(examples_path / "Old_examples" / "AutoConnectWithFeedback") in examples + assert str(examples_path / "Old_examples" / "AutoConnectWithReset") in examples + assert str(examples_path / "Old_examples" / "AutoConnectWithStaticIP") in examples + assert str(examples_path / "Old_examples" / "AutoConnectWithTimeout") in examples + assert str(examples_path / "OnDemand" / "OnDemandConfigPortal") in examples + assert str(examples_path / "ParamsChildClass") in examples + + # Verifies sketches with wrong casing are not returned + assert str(examples_path / "NonBlocking" / "OnDemandNonBlocking") not in examples + assert str(examples_path / "OnDemand" / "OnDemandWebPortal") not in examples diff --git a/test/test_sketch.py b/test/test_sketch.py index d3fb4126faa..35e8b4fd615 100644 --- a/test/test_sketch.py +++ b/test/test_sketch.py @@ -846,3 +846,17 @@ def test_sketch_archive_with_multiple_main_files(run_command, copy_sketch, worki assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr assert str(sketch_file.relative_to(sketch_dir)) in res.stderr assert "Error archiving: multiple main sketch files found" in res.stderr + + +def test_sketch_archive_case_mismatch_fails(run_command, data_dir): + sketch_name = "ArchiveSketchCaseMismatch" + sketch_path = Path(data_dir, sketch_name) + + assert run_command(f"sketch new {sketch_path}") + + # Rename main .ino file so casing is different from sketch name + Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino") + + res = run_command(f'sketch archive "{sketch_path}"') + assert res.failed + assert "Error archiving: no valid sketch found" in res.stderr diff --git a/test/test_upload.py b/test/test_upload.py index 7f8d272a822..36a65c115d9 100644 --- a/test/test_upload.py +++ b/test/test_upload.py @@ -337,3 +337,48 @@ def test_upload_with_input_dir_containing_multiple_binaries(run_command, data_di assert ( "Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr ) + + +def test_compile_and_upload_combo_sketch_with_mismatched_casing(run_command, data_dir, detected_boards, wait_for_board): + assert run_command("update") + + # Create a sketch + sketch_name = "CompileUploadComboMismatchCasing" + sketch_path = Path(data_dir, sketch_name) + assert run_command(f"sketch new {sketch_path}") + + # Rename main .ino file so casing is different from sketch name + Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino") + + for board in detected_boards: + # Install core + core = ":".join(board.fqbn.split(":")[:2]) + assert run_command(f"core install {core}") + + # Try to compile + res = run_command(f"compile --clean -b {board.fqbn} -u -p {board.address} {sketch_path}") + assert res.failed + assert "Error during build: opening sketch: no valid sketch found" in res.stderr + + +def test_upload_sketch_with_mismatched_casing(run_command, data_dir, detected_boards, wait_for_board): + assert run_command("update") + + # Create a sketch + sketch_name = "UploadMismatchCasing" + sketch_path = Path(data_dir, sketch_name) + assert run_command(f"sketch new {sketch_path}") + + # Rename main .ino file so casing is different from sketch name + Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino") + + for board in detected_boards: + # Install core + core = ":".join(board.fqbn.split(":")[:2]) + assert run_command(f"core install {core}") + + # Tries to upload given sketch, it has not been compiled but it fails even before + # searching for binaries since the sketch is not valid + res = run_command(f"upload -b {board.fqbn} -p {board.address} {sketch_path}") + assert res.failed + assert "Error during Upload: opening sketch: no valid sketch found" in res.stderr