Skip to content

Commit 6a8a9f1

Browse files
Migrate TestCompileWithInvalidUrl from test_compile_part_2.py to compile_part_2_test.go
1 parent 76b7003 commit 6a8a9f1

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

internal/integrationtest/compile/compile_part_2_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,33 @@ func TestCompileWithCustomBuildPath(t *testing.T) {
150150
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
151151
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
152152
}
153+
154+
func TestCompileWithInvalidUrl(t *testing.T) {
155+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
156+
defer env.CleanUp()
157+
158+
// Init the environment explicitly
159+
_, _, err := cli.Run("core", "update-index")
160+
require.NoError(t, err)
161+
162+
// Download latest AVR
163+
_, _, err = cli.Run("core", "install", "arduino:avr")
164+
require.NoError(t, err)
165+
166+
sketchName := "CompileWithInvalidURL"
167+
sketchPath := cli.SketchbookDir().Join(sketchName)
168+
fqbn := "arduino:avr:uno"
169+
170+
// Create a test sketch
171+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
172+
require.NoError(t, err)
173+
174+
_, _, err = cli.Run("config", "init", "--dest-dir", ".", "--additional-urls", "https://example.com/package_example_index.json")
175+
require.NoError(t, err)
176+
177+
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
178+
require.NoError(t, err)
179+
require.Contains(t, string(stderr), "Error initializing instance: Loading index file: loading json index file")
180+
expectedIndexfile := cli.DataDir().Join("package_example_index.json")
181+
require.Contains(t, string(stderr), "loading json index file "+expectedIndexfile.String()+": open "+expectedIndexfile.String()+":")
182+
}

test/test_compile_part_2.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,6 @@ def test_compile_with_export_binaries_config(run_command, data_dir, downloads_di
9090
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.hex").exists()
9191

9292

93-
def test_compile_with_invalid_url(run_command, data_dir):
94-
# Init the environment explicitly
95-
run_command(["core", "update-index"])
96-
97-
# Download latest AVR
98-
run_command(["core", "install", "arduino:avr"])
99-
100-
sketch_name = "CompileWithInvalidURL"
101-
sketch_path = Path(data_dir, sketch_name)
102-
fqbn = "arduino:avr:uno"
103-
104-
# Create a test sketch
105-
assert run_command(["sketch", "new", sketch_path])
106-
107-
# Create settings with custom invalid URL
108-
assert run_command(
109-
["config", "init", "--dest-dir", ".", "--additional-urls", "https://example.com/package_example_index.json"]
110-
)
111-
112-
# Verifies compilation fails cause of missing local index file
113-
res = run_command(["compile", "-b", fqbn, sketch_path])
114-
assert res.ok
115-
lines = [l.strip() for l in res.stderr.splitlines()]
116-
assert "Error initializing instance: Loading index file: loading json index file" in lines[0]
117-
expected_index_file = Path(data_dir, "package_example_index.json")
118-
assert f"loading json index file {expected_index_file}: " + f"open {expected_index_file}:" in lines[-1]
119-
120-
12193
def test_compile_with_custom_libraries(run_command, copy_sketch):
12294
# Creates config with additional URL to install necessary core
12395
url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"

0 commit comments

Comments
 (0)