From 7e0fbec2a37089adc9d9ef66d28f129dbca96c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 2 May 2024 16:23:16 +0100 Subject: [PATCH] cmd/cue: add tests that cover fmt on various filetypes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I will soon refactor fmt slightly to no longer use internal/encoding, so I want to make sure we don't add unintended regressions. A couple of these are probably not the right behavior, hence the TODOs. Signed-off-by: Daniel Martí Change-Id: Ife85cb31a0f2414dca42345d99c6390d748ff3c9 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194199 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Noam Dolovich Reviewed-by: Paul Jolly --- .../cmd/testdata/script/fmt_filetypes.txtar | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 cmd/cue/cmd/testdata/script/fmt_filetypes.txtar diff --git a/cmd/cue/cmd/testdata/script/fmt_filetypes.txtar b/cmd/cue/cmd/testdata/script/fmt_filetypes.txtar new file mode 100644 index 00000000000..c61be3e227e --- /dev/null +++ b/cmd/cue/cmd/testdata/script/fmt_filetypes.txtar @@ -0,0 +1,63 @@ +# Verify how fmt behaves with different encodings. + +exec cue fmt --diff input.cue +cmp stdout input.cue.diff + +# Unknown file extensions fail on their own +! exec cue fmt --diff input.cue-unknown +stderr 'unknown file extension' + +# Unknown file extensions work if we specify them as CUE. +cp input.cue input.cue-unknown +exec cue fmt --diff cue: input.cue-unknown +cmp stdout input.cue-unknown.diff + +# TODO(mvdan): we should probably fail rather than doing nothing. +exec cue fmt --diff input.json +! stdout . +! stderr . + +# JSON is valid CUE syntax, so it can be formatted as CUE, if one wants to. +exec cue fmt --diff cue: input.json +cmp stdout input.json.diff + +# TODO(mvdan): we should probably fail rather than doing nothing. +exec cue fmt --diff input.yaml +! stdout . +! stderr . + +# YAML in this case is not valid CUE. +! exec cue fmt --diff cue: input.yaml +stderr 'in struct literal' + +-- input.cue -- +foo: "bar" +-- input.cue.diff -- +diff input.cue.orig input.cue +--- input.cue.orig ++++ input.cue +@@ -1,1 +1,1 @@ +-foo: "bar" ++foo: "bar" + +-- input.cue-unknown.diff -- +diff input.cue-unknown.orig input.cue-unknown +--- input.cue-unknown.orig ++++ input.cue-unknown +@@ -1,1 +1,1 @@ +-foo: "bar" ++foo: "bar" + +-- input.json -- +{"foo": "bar"} +-- input.json.diff -- +diff input.json.orig input.json +--- input.json.orig ++++ input.json +@@ -1,1 +1,1 @@ +-{"foo": "bar"} ++{"foo": "bar"} + +-- input.yaml -- +foo: +- unquoted bar