Skip to content

Fix preprocess output (do not print stats after the preprocessed source) #2152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
ProfileOut: profileOut,
Success: compileError == nil,
showPropertiesMode: showProperties,
hideStats: preprocess,
}

if compileError != nil {
Expand Down Expand Up @@ -394,6 +395,7 @@ type compileResult struct {
Error string `json:"error,omitempty"`

showPropertiesMode arguments.ShowPropertiesMode
hideStats bool
}

func (r *compileResult) Data() interface{} {
Expand All @@ -405,6 +407,10 @@ func (r *compileResult) String() string {
return strings.Join(r.BuilderResult.GetBuildProperties(), fmt.Sprintln())
}

if r.hideStats {
return ""
}

titleColor := color.New(color.FgHiGreen)
nameColor := color.New(color.FgHiYellow)
pathColor := color.New(color.FgHiBlack)
Expand Down
43 changes: 43 additions & 0 deletions internal/integrationtest/compile_1/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"
"time"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestCompile(t *testing.T) {
{"WithInvalidBuildOptionJson", compileWithInvalidBuildOptionJson},
{"WithRelativeBuildPath", compileWithRelativeBuildPath},
{"WithFakeSecureBootCore", compileWithFakeSecureBootCore},
{"PreprocessFlagDoNotMessUpWithOutput", preprocessFlagDoNotMessUpWithOutput},
}.Run(t, env, cli)
}

Expand Down Expand Up @@ -1162,3 +1164,44 @@ func compileWithFakeSecureBootCore(t *testing.T, env *integrationtest.Environmen
require.Contains(t, string(stdout), "my-sign-key.pem")
require.Contains(t, string(stdout), "my-encrypt-key.pem")
}

func preprocessFlagDoNotMessUpWithOutput(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
// https://github.com/arduino/arduino-cli/issues/2150

// go test -v ./internal/integrationtest/compile_1 --run=TestCompile$/PreprocessFlagDoNotMessUpWithOutput

sketchPath := cli.SketchbookDir().Join("SketchSimple")
defer sketchPath.RemoveAll()
fqbn := "arduino:avr:uno"
_, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)

expected := `#include <Arduino.h>
#line 1 %SKETCH_PATH%

#line 2 %SKETCH_PATH%
void setup();
#line 5 %SKETCH_PATH%
void loop();
#line 2 %SKETCH_PATH%
void setup() {
}

void loop() {
}

`
expected = strings.ReplaceAll(expected, "%SKETCH_PATH%", builder.QuoteCppString(sketchPath.Join("SketchSimple.ino").String()))

jsonOut, _, err := cli.Run("compile", "-b", fqbn, "--preprocess", sketchPath.String(), "--format", "json")
require.NoError(t, err)
var ex struct {
CompilerOut string `json:"compiler_out"`
}
require.NoError(t, json.Unmarshal(jsonOut, &ex))
require.Equal(t, expected, ex.CompilerOut)

output, _, err := cli.Run("compile", "-b", fqbn, "--preprocess", sketchPath.String())
require.NoError(t, err)
require.Equal(t, expected, string(output))
}