Skip to content

Commit fb631bd

Browse files
committed
cmd/cue: add testscript for issue 4009
With `cue: /dev/stdin` we attempt to read the file twice, and the second time there are no bytes to be consumed, hence we export an empty struct. For #4009. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I53b203929f4af779cdc2a50bb733b9960466cabd Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1219437 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 4bdc446 commit fb631bd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Issue 4009
2+
# cue/load parses input CUE files more than once; for example,
3+
# first to only parse the imports, and later to parse the whole file.
4+
# Reading an input file multiple times only works if it's a regular file.
5+
# Make sure that the various ways to consume stdin do not attempt
6+
# to open or read the file more than once.
7+
8+
# Sanity check: use the regular file.
9+
exec cue export cue: other
10+
cmp stdout export.stdout
11+
12+
# Use Go's os.Stdin directly.
13+
stdin other
14+
exec cue export cue: -
15+
cmp stdout export.stdout
16+
17+
# Use /dev/stdin, a device file pointing to stdin.
18+
[!unix] stop # /dev/stdin is not present on Windows
19+
stdin other
20+
exec cue export cue: /dev/stdin
21+
cmp stdout export-broken.stdout
22+
23+
-- cue.mod/module.cue --
24+
module: "foo.test"
25+
language: version: "v0.13.0"
26+
-- other --
27+
foo: "bar"
28+
-- export.stdout --
29+
{
30+
"foo": "bar"
31+
}
32+
-- export-broken.stdout --
33+
{}

0 commit comments

Comments
 (0)