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