@@ -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
@@ -1162,3 +1164,44 @@ func compileWithFakeSecureBootCore(t *testing.T, env *integrationtest.Environmen
1162
1164
require .Contains (t , string (stdout ), "my-sign-key.pem" )
1163
1165
require .Contains (t , string (stdout ), "my-encrypt-key.pem" )
1164
1166
}
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