Skip to content

Commit 89d1180

Browse files
Migrate TestCompileWithInvalidBuildOptionJson from test_compile_part_4.py to compile_part_4_test.go
1 parent c620dfb commit 89d1180

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

internal/integrationtest/compile/compile_part_4_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,39 @@ func TestCompileWithConflictingLibrariesInclude(t *testing.T) {
218218
}
219219
require.Contains(t, string(stdout), expectedOutput[0]+"\n"+expectedOutput[1]+"\n"+expectedOutput[2]+"\n")
220220
}
221+
222+
func TestCompileWithInvalidBuildOptionJson(t *testing.T) {
223+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
224+
defer env.CleanUp()
225+
226+
_, _, err := cli.Run("update")
227+
require.NoError(t, err)
228+
229+
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
230+
require.NoError(t, err)
231+
232+
sketchName := "CompileInvalidBuildOptionsJson"
233+
sketchPath := cli.SketchbookDir().Join(sketchName)
234+
fqbn := "arduino:avr:uno"
235+
236+
// Create a test sketch
237+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
238+
require.NoError(t, err)
239+
240+
// Get the build directory
241+
md5 := md5.Sum(([]byte(sketchPath.String())))
242+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
243+
require.NotEmpty(t, sketchPathMd5)
244+
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
245+
246+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose")
247+
require.NoError(t, err)
248+
249+
// Breaks the build.options.json file
250+
buildOptionsJson := buildDir.Join("build.options.json")
251+
err = buildOptionsJson.WriteFile([]byte("invalid json"))
252+
require.NoError(t, err)
253+
254+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose")
255+
require.NoError(t, err)
256+
}

test/test_compile_part_4.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,6 @@ def test_compile_manually_installed_platform_using_boards_local_txt(run_command,
5050
assert run_command(["compile", "--clean", "-b", fqbn, sketch_path])
5151

5252

53-
def test_compile_with_invalid_build_options_json(run_command, data_dir):
54-
assert run_command(["update"])
55-
56-
assert run_command(["core", "install", "arduino:avr@1.8.3"])
57-
58-
sketch_name = "CompileInvalidBuildOptionsJson"
59-
sketch_path = Path(data_dir, sketch_name)
60-
fqbn = "arduino:avr:uno"
61-
62-
# Create a test sketch
63-
assert run_command(["sketch", "new", sketch_path])
64-
65-
# Get the build directory
66-
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
67-
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
68-
69-
assert run_command(["compile", "-b", fqbn, sketch_path, "--verbose"])
70-
71-
# Breaks the build.options.json file
72-
build_options_json = build_dir / "build.options.json"
73-
with open(build_options_json, "w") as f:
74-
f.write("invalid json")
75-
76-
assert run_command(["compile", "-b", fqbn, sketch_path, "--verbose"])
77-
78-
7953
def test_compile_with_esp32_bundled_libraries(run_command, data_dir, copy_sketch):
8054
# Some esp cores have have bundled libraries that are optimize for that architecture,
8155
# it might happen that if the user has a library with the same name installed conflicts

0 commit comments

Comments
 (0)