Skip to content

Commit

Permalink
cmd/cue: add a test for embedding symbolic links
Browse files Browse the repository at this point in the history
Valid symbolic links are currently allowed, but that will change
in the next commit. This test allows us to see the change in behavior.

While here, add more error test cases for embedding as well.
In particular, the "cannot embed directories" and invalid filetype
error code paths were not covered in the tests.

For #3299.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I5f80b1dc81e2a2bd13bd084be74cabec6f205ba4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199032
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
  • Loading branch information
mvdan committed Aug 7, 2024
1 parent bcbc7cd commit 4d941df
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions cmd/cue/cmd/testdata/script/embed_err.txtar
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
env CUE_EXPERIMENT=embed

! exec cue eval
cmp stdout out/std
! stdout .
cmp stderr out/err

# On systems with symlink support, check that we don't allow embedding symlinks.
# TODO(mvdan): we don't reject valid symlinks yet; see https://cuelang.org/issue/3299.
# TODO: if we support symlinks in the future, add a test case for a symlink pointing to a file
# outside of the current module, as that should likely be forbidden.
[!symlink] stop
cd symlink
symlink symlink.json -> test.json
symlink symlink-parent.json -> ../test.json
exec cue eval .
cmp stdout out/std

-- test.cue --
@extern(embed)

Expand Down Expand Up @@ -59,6 +70,13 @@ unspecifiedFiletype4: _ @embed(glob=x/*.[j]son)
nestedModJSON: _ @embed(file="a/b/foo.json")
nestedModJSONWithGlob: _ @embed(glob="a/*/*.json")

directory: _ @embed(file="x", type=cue)

buildFailure: _ @embed(file="buildfail.cue")

invalidFiletype: _ @embed(file="x.unknown")
invalidPattern: _ @embed(glob="x[")

-- test.json --
{ "x": 34 }
-- test.ldjson --
Expand All @@ -83,12 +101,13 @@ a: 1
x: 5
-- xcue --
x: 5
-- buildfail.cue --
x: 5 & >10
-- a/b/cue.mod/modules.cue --
module: "acme.com"
language: version: "v0.9.0"
-- a/b/foo.json --
{"a": 1, "b": 2}
-- out/std --
-- out/err --
@embed: attribute must have file or glob field:
./test.cue:5:8
Expand Down Expand Up @@ -142,3 +161,36 @@ language: version: "v0.9.0"
./test.cue:52:18
@embed: cannot embed file "a/b/foo.json": in different module:
./test.cue:53:26
@embed: cannot embed directories:
./test.cue:55:14
@embed: encoding "cue" not (yet) supported:
./test.cue:57:17
@embed: unknown file extension .unknown:
./test.cue:59:20
@embed: invalid glob pattern "x[": syntax error in pattern:
./test.cue:60:19
-- symlink/test.cue --
@extern(embed)

package symlink

file: _ @embed(file=symlink.json)

glob: _ @embed(glob="*.json")
-- symlink/test.json --
{ "x": "symlink target file" }
-- symlink/out/std --
file: {
x: "symlink target file"
}
glob: {
"symlink-parent.json": {
x: 34
}
"symlink.json": {
x: "symlink target file"
}
"test.json": {
x: "symlink target file"
}
}

0 comments on commit 4d941df

Please sign in to comment.