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