-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/cmd: always write stdin to stdout in cue fmt
A recent CL (https://cuelang.org/cl/1193934) modified cue fmt to only write to files in case they were not well formatted. A bug was introduced by this change, in which `cue fmt -` would only write to stdout in case the standard input was not formatted. This is not correct, as users would expect there to always be output in this case. This is fixed by always writing the provided stdin to stdout, regardless of whether it was well formatted or not. Fixes #3067. Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Id69a50c454c3871ec56526de2cd622cdd6ded730 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193969 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Paul Jolly <paul@myitcv.io> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
- Loading branch information
Showing
3 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
stdin feed | ||
# Verify that `cue fmt -` always writes valid CUE provided | ||
# in stdin to stdout, even if it is well formatted. | ||
|
||
stdin not-formatted | ||
exec cue fmt - | ||
cmp stdout formatted | ||
|
||
stdin formatted | ||
exec cue fmt - | ||
cmp stdout expect-stdout | ||
cmp stdout formatted | ||
|
||
# Verify that `cue fmt -` does not write invalid CUE to stdout. | ||
stdin syntax-error | ||
! exec cue fmt - | ||
! stdout . | ||
cmp stderr syntax-error.stderr-golden | ||
|
||
-- feed -- | ||
-- syntax-error -- | ||
a: { | ||
-- syntax-error.stderr-golden -- | ||
expected '}', found 'EOF': | ||
-:1:6 | ||
-- not-formatted -- | ||
foo : 2 | ||
a: {b: 3} // a comment | ||
-- expect-stdout -- | ||
-- formatted -- | ||
foo: 2 | ||
a: {b: 3} // a comment | ||
-- fmt/cue.mod/module.cue -- |