Skip to content

Commit da09041

Browse files
committed
Added test
1 parent bfb5f3f commit da09041

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Diff for: internal/integrationtest/compile_1/compile_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28+
"github.com/arduino/arduino-cli/arduino/builder"
2829
"github.com/arduino/arduino-cli/internal/integrationtest"
2930
"github.com/arduino/go-paths-helper"
3031
"github.com/stretchr/testify/require"
@@ -71,6 +72,7 @@ func TestCompile(t *testing.T) {
7172
{"WithInvalidBuildOptionJson", compileWithInvalidBuildOptionJson},
7273
{"WithRelativeBuildPath", compileWithRelativeBuildPath},
7374
{"WithFakeSecureBootCore", compileWithFakeSecureBootCore},
75+
{"PreprocessFlagDoNotMessUpWithOutput", preprocessFlagDoNotMessUpWithOutput},
7476
}.Run(t, env, cli)
7577
}
7678

@@ -1164,3 +1166,44 @@ func compileWithFakeSecureBootCore(t *testing.T, env *integrationtest.Environmen
11641166
require.Contains(t, string(stdout), "my-sign-key.pem")
11651167
require.Contains(t, string(stdout), "my-encrypt-key.pem")
11661168
}
1169+
1170+
func preprocessFlagDoNotMessUpWithOutput(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
1171+
// https://github.com/arduino/arduino-cli/issues/2150
1172+
1173+
// go test -v ./internal/integrationtest/compile_1 --run=TestCompile$/PreprocessFlagDoNotMessUpWithOutput
1174+
1175+
sketchPath := cli.SketchbookDir().Join("SketchSimple")
1176+
defer sketchPath.RemoveAll()
1177+
fqbn := "arduino:avr:uno"
1178+
_, _, err := cli.Run("sketch", "new", sketchPath.String())
1179+
require.NoError(t, err)
1180+
1181+
expected := `#include <Arduino.h>
1182+
#line 1 %SKETCH_PATH%
1183+
1184+
#line 2 %SKETCH_PATH%
1185+
void setup();
1186+
#line 5 %SKETCH_PATH%
1187+
void loop();
1188+
#line 2 %SKETCH_PATH%
1189+
void setup() {
1190+
}
1191+
1192+
void loop() {
1193+
}
1194+
1195+
`
1196+
expected = strings.ReplaceAll(expected, "%SKETCH_PATH%", builder.QuoteCppString(sketchPath.Join("SketchSimple.ino").String()))
1197+
1198+
jsonOut, _, err := cli.Run("compile", "-b", fqbn, "--preprocess", sketchPath.String(), "--format", "json")
1199+
require.NoError(t, err)
1200+
var ex struct {
1201+
CompilerOut string `json:"compiler_out"`
1202+
}
1203+
require.NoError(t, json.Unmarshal(jsonOut, &ex))
1204+
require.Equal(t, expected, ex.CompilerOut)
1205+
1206+
output, _, err := cli.Run("compile", "-b", fqbn, "--preprocess", sketchPath.String())
1207+
require.NoError(t, err)
1208+
require.Equal(t, expected, string(output))
1209+
}

0 commit comments

Comments
 (0)