@@ -25,6 +25,7 @@ import (
25
25
"testing"
26
26
"time"
27
27
28
+ "github.com/arduino/arduino-cli/arduino/builder"
28
29
"github.com/arduino/arduino-cli/internal/integrationtest"
29
30
"github.com/arduino/go-paths-helper"
30
31
"github.com/stretchr/testify/require"
@@ -71,6 +72,7 @@ func TestCompile(t *testing.T) {
71
72
{"WithInvalidBuildOptionJson" , compileWithInvalidBuildOptionJson },
72
73
{"WithRelativeBuildPath" , compileWithRelativeBuildPath },
73
74
{"WithFakeSecureBootCore" , compileWithFakeSecureBootCore },
75
+ {"PreprocessFlagDoNotMessUpWithOutput" , preprocessFlagDoNotMessUpWithOutput },
74
76
}.Run (t , env , cli )
75
77
}
76
78
@@ -1164,3 +1166,44 @@ func compileWithFakeSecureBootCore(t *testing.T, env *integrationtest.Environmen
1164
1166
require .Contains (t , string (stdout ), "my-sign-key.pem" )
1165
1167
require .Contains (t , string (stdout ), "my-encrypt-key.pem" )
1166
1168
}
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