Skip to content

Commit 5512924

Browse files
Migrated TestCompileWithBuildPropertiesFlag from test_compile_part_1.py to compile_part_1_test.go
1 parent fd144f6 commit 5512924

File tree

5 files changed

+100
-75
lines changed

5 files changed

+100
-75
lines changed

internal/integrationtest/compile/compile_part_1_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,71 @@ func TestCompileWithoutPrecompiledLibraries(t *testing.T) {
312312
_, _, err = cli.Run("compile", "-b", "arduino:samd:mkrvidor4000", sketchPath.String())
313313
require.NoError(t, err)
314314
}
315+
316+
func TestCompileWithBuildPropertiesFlag(t *testing.T) {
317+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
318+
defer env.CleanUp()
319+
320+
// Init the environment explicitly
321+
_, _, err := cli.Run("core", "update-index")
322+
require.NoError(t, err)
323+
324+
// Install Arduino AVR Boards
325+
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
326+
require.NoError(t, err)
327+
328+
// Copy sketch
329+
sketchName := "sketch_with_single_string_define"
330+
p, err := paths.Getwd()
331+
require.NoError(t, err)
332+
require.NotNil(t, p)
333+
testSketch := p.Parent().Join("testdata", sketchName)
334+
sketchPath := cli.SketchbookDir().Join(sketchName)
335+
err = testSketch.CopyDirTo(sketchPath)
336+
require.NoError(t, err)
337+
338+
fqbn := "arduino:avr:uno"
339+
340+
// Compile using a build property with quotes
341+
_, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"", sketchPath.String(), "--verbose", "--clean")
342+
require.Error(t, err)
343+
require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
344+
345+
// Try again with quotes
346+
_, stderr, err = cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=\"hello\"\"", sketchPath.String(), "--verbose", "--clean")
347+
require.Error(t, err)
348+
require.NotContains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
349+
350+
// Copy sketch
351+
sketchName = "sketch_with_single_int_define"
352+
testSketch = p.Parent().Join("testdata", sketchName)
353+
sketchPath = cli.SketchbookDir().Join(sketchName)
354+
err = testSketch.CopyDirTo(sketchPath)
355+
require.NoError(t, err)
356+
357+
// Try without quotes
358+
stdout, stderr, err := cli.Run("compile", "-b", fqbn, "--build-properties=\"build.extra_flags=-DMY_DEFINE=1\"", sketchPath.String(), "--verbose", "--clean")
359+
require.NoError(t, err)
360+
require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
361+
require.Contains(t, string(stdout), "-DMY_DEFINE=1")
362+
363+
// Copy sketch
364+
sketchName = "sketch_with_multiple_int_defines"
365+
testSketch = p.Parent().Join("testdata", sketchName)
366+
sketchPath = cli.SketchbookDir().Join(sketchName)
367+
err = testSketch.CopyDirTo(sketchPath)
368+
require.NoError(t, err)
369+
370+
stdout, stderr, err = cli.Run("compile",
371+
"-b",
372+
fqbn,
373+
"--build-properties",
374+
"build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2",
375+
sketchPath.String(),
376+
"--verbose",
377+
"--clean")
378+
require.NoError(t, err)
379+
require.Contains(t, string(stderr), "Flag --build-properties has been deprecated, please use --build-property instead.")
380+
require.Contains(t, string(stdout), "-DFIRST_PIN=1")
381+
require.Contains(t, string(stdout), "-DSECOND_PIN=2")
382+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
const int MY_FIRST_PIN = FIRST_PIN;
3+
const int MY_SECOND_PIN = SECOND_PIN;
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
Serial.println(MY_FIRST_PIN);
8+
Serial.println(MY_SECOND_PIN);
9+
}
10+
11+
void loop() {
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const int FOO = MY_DEFINE;
3+
4+
void setup() {
5+
Serial.begin(9600);
6+
Serial.println(FOO);
7+
}
8+
9+
void loop() {
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const String FOO = MY_DEFINE;
3+
4+
void setup() {
5+
Serial.begin(9600);
6+
Serial.println(FOO);
7+
}
8+
9+
void loop() {
10+
}

test/test_compile_part_1.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -60,81 +60,6 @@ def test_compile_without_precompiled_libraries(run_command, data_dir):
6060
assert run_command(["compile", "-b", "arduino:samd:mkrvidor4000", sketch_path])
6161

6262

63-
def test_compile_with_build_properties_flag(run_command, data_dir, copy_sketch):
64-
# Init the environment explicitly
65-
assert run_command(["core", "update-index"])
66-
67-
# Install Arduino AVR Boards
68-
assert run_command(["core", "install", "arduino:avr@1.8.3"])
69-
70-
sketch_path = copy_sketch("sketch_with_single_string_define")
71-
fqbn = "arduino:avr:uno"
72-
73-
# Compile using a build property with quotes
74-
res = run_command(
75-
[
76-
"compile",
77-
"-b",
78-
fqbn,
79-
'--build-properties="build.extra_flags=\\"-DMY_DEFINE=\\"hello world\\"\\""',
80-
sketch_path,
81-
"--verbose",
82-
"--clean",
83-
]
84-
)
85-
assert res.failed
86-
assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res.stderr
87-
88-
# Try again with quotes
89-
res = run_command(
90-
[
91-
"compile",
92-
"-b",
93-
fqbn,
94-
'--build-properties="build.extra_flags=-DMY_DEFINE=\\"hello\\""',
95-
sketch_path,
96-
"--verbose",
97-
"--clean",
98-
]
99-
)
100-
assert res.failed
101-
assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res.stderr
102-
103-
# Try without quotes
104-
sketch_path = copy_sketch("sketch_with_single_int_define")
105-
res = run_command(
106-
[
107-
"compile",
108-
"-b",
109-
fqbn,
110-
'--build-properties="build.extra_flags=-DMY_DEFINE=1"',
111-
sketch_path,
112-
"--verbose",
113-
"--clean",
114-
]
115-
)
116-
assert res.ok
117-
assert "Flag --build-properties has been deprecated, please use --build-property instead." in res.stderr
118-
assert "-DMY_DEFINE=1" in res.stdout
119-
120-
sketch_path = copy_sketch("sketch_with_multiple_int_defines")
121-
res = run_command(
122-
[
123-
"compile",
124-
"-b",
125-
fqbn,
126-
'--build-properties="build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2"',
127-
sketch_path,
128-
"--verbose",
129-
"--clean",
130-
]
131-
)
132-
assert res.ok
133-
assert "Flag --build-properties has been deprecated, please use --build-property instead." in res.stderr
134-
assert "-DFIRST_PIN=1" in res.stdout
135-
assert "-DSECOND_PIN=2" in res.stdout
136-
137-
13863
def test_compile_with_build_property_containing_quotes(run_command, data_dir, copy_sketch):
13964
# Init the environment explicitly
14065
assert run_command(["core", "update-index"])

0 commit comments

Comments
 (0)