Skip to content

Commit

Permalink
cmd/cue: add regression test for 'cue cmd' with many packages
Browse files Browse the repository at this point in the history
Thanks to Paul Jolly for writing the testscript in a comment on #1325.
It is added here with some minor tweaks: adding more comments,
and reflecting the current behavior with the last command failing.

Without such a test, it's hard to notice when we might break users
who rely on the existing behavior, intentionally or not.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I82d0229d085e8d63fc3e170e2c92f66434159117
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193717
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
  • Loading branch information
mvdan committed Apr 24, 2024
1 parent a16a054 commit 994a15d
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_many.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Test cue cmd's behavior when given multiple packages.
# Note that we're not sure if this is the behavior we want long term,
# but it is the behavior we have had for some time, and some users
# are currently reliant on it. See https://cuelang.org/issue/1325.

# Export with itemsList_tool.cue in place.
exec cue export ./...
cmp stdout stdout.export-pre.golden

# Verify that cue cmd ls ./... works.
# Note that a single ls command is run with a single package value
# reuslting from the unification of all packages in ./...
exec cue cmd ls ./...
cmp stdout stdout.ls-pre.golden

# Now rename itemsList_tool.cue to itemsList.cue.
mv itemsList_tool.cue itemsList.cue

# Export with itemsList.cue in place.
exec cue export ./...
cmp stdout stdout.export-post.golden

# Attempt to ls in this state, which fails, as each of the CUE packages
# hold an items list with different lengths.
! exec cue cmd ls ./...
stderr 'itemsList: incompatible list lengths \(0 and 1\)'

-- cue.mod/module.cue --
module: "mod.com"
-- x.cue --
package x

items: {}
-- ls_tool.cue --
package x

import (
"tool/cli"
"strings"
)

command: ls: cli.Print & {
text: "ls: " + strings.Join(itemsList, " ") + "\n"
}
-- itemsList_tool.cue --
package x

itemsList: [for _, v in items {v}]
-- a/x.cue --
package x

items: {
a: "a"
}
-- b/x.cue --
package x

items: {
b: "b"
}
-- stdout.export-pre.golden --
{
"items": {}
}
{
"items": {
"a": "a"
}
}
{
"items": {
"b": "b"
}
}
-- stdout.ls-pre.golden --
ls: a b

-- stdout.export-post.golden --
{
"itemsList": [],
"items": {}
}
{
"itemsList": [
"a"
],
"items": {
"a": "a"
}
}
{
"itemsList": [
"b"
],
"items": {
"b": "b"
}
}

0 comments on commit 994a15d

Please sign in to comment.