Skip to content

Commit 4cdd9f1

Browse files
Migrate TestCompileSketchCaseMismatchFails from test_compile_part_3.py to compile_part_3_test.go
A new that sets the working directory to a specific path has been added in order to run all the tests as intended.
1 parent 2b71d9c commit 4cdd9f1

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

internal/integrationtest/arduino-cli.go

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ func (cli *ArduinoCLI) WorkingDir() *paths.Path {
137137
return cli.workingDir
138138
}
139139

140+
// SetWorkingDir sets a new working directory
141+
func (cli *ArduinoCLI) SetWorkingDir(p *paths.Path) {
142+
cli.workingDir = p
143+
}
144+
140145
// CopySketch copies a sketch inside the testing environment and returns its path
141146
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
142147
p, err := paths.Getwd()

internal/integrationtest/compile/compile_part_3_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package compile_part_1_test
1717

1818
import (
19+
"strings"
1920
"testing"
2021

2122
"github.com/arduino/arduino-cli/internal/integrationtest"
@@ -101,3 +102,44 @@ func TestCompileSketchWithMultipleMainFiles(t *testing.T) {
101102
require.Error(t, err)
102103
require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found")
103104
}
105+
106+
func TestCompileSketchCaseMismatchFails(t *testing.T) {
107+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
108+
defer env.CleanUp()
109+
110+
// Init the environment explicitly
111+
_, _, err := cli.Run("update")
112+
require.NoError(t, err)
113+
114+
// Install core to compile
115+
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
116+
require.NoError(t, err)
117+
118+
sketchName := "CompileSketchCaseMismatch"
119+
sketchPath := cli.SketchbookDir().Join(sketchName)
120+
fqbn := "arduino:avr:uno"
121+
122+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
123+
require.NoError(t, err)
124+
125+
// Rename main .ino file so casing is different from sketch name
126+
sketchFile := sketchPath.Join(sketchName + ".ino")
127+
sketchMainFile := sketchPath.Join(strings.ToLower(sketchName) + ".ino")
128+
err = sketchFile.Rename(sketchMainFile)
129+
require.NoError(t, err)
130+
131+
// Verifies compilation fails when:
132+
// * Compiling with sketch path
133+
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
134+
require.Error(t, err)
135+
require.Contains(t, string(stderr), "Error opening sketch:")
136+
// * Compiling with sketch main file
137+
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchMainFile.String())
138+
require.Error(t, err)
139+
require.Contains(t, string(stderr), "Error opening sketch:")
140+
// * Compiling in sketch path
141+
cli.SetWorkingDir(sketchPath)
142+
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn)
143+
require.Error(t, err)
144+
require.Contains(t, string(stderr), "Error opening sketch:")
145+
}

test/test_compile_part_3.py

-31
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,6 @@
3939
# assert "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite" in result.stdout
4040

4141

42-
def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
43-
# Init the environment explicitly
44-
assert run_command(["update"])
45-
46-
# Install core to compile
47-
assert run_command(["core", "install", "arduino:[email protected]"])
48-
49-
sketch_name = "CompileSketchCaseMismatch"
50-
sketch_path = Path(data_dir, sketch_name)
51-
fqbn = "arduino:avr:uno"
52-
53-
assert run_command(["sketch", "new", sketch_path])
54-
55-
# Rename main .ino file so casing is different from sketch name
56-
sketch_main_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name.lower()}.ino")
57-
58-
# Verifies compilation fails when:
59-
# * Compiling with sketch path
60-
res = run_command(["compile", "--clean", "-b", fqbn, sketch_path])
61-
assert res.failed
62-
assert "Error opening sketch:" in res.stderr
63-
# * Compiling with sketch main file
64-
res = run_command(["compile", "--clean", "-b", fqbn, sketch_main_file])
65-
assert res.failed
66-
assert "Error opening sketch:" in res.stderr
67-
# * Compiling in sketch path
68-
res = run_command(["compile", "--clean", "-b", fqbn], custom_working_dir=sketch_path)
69-
assert res.failed
70-
assert "Error opening sketch:" in res.stderr
71-
72-
7342
def test_compile_with_only_compilation_database_flag(run_command, data_dir):
7443
assert run_command(["update"])
7544

0 commit comments

Comments
 (0)