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

# On systems with symlink support, we follow symlinks when embedding files.
# TODO: 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
symlink symlink-dir -> y
exec cue eval .
cmp stdout out/std

-- cue.mod/module.cue --
module: "cue.example"
language: version: "v0.11.0"

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

package foo

none: _@embed(type=foo)

both: _ @embed(file=test.json, glob="x/*.*", type=yaml)

dotdot: _ @embed(file="../test.json")

abs: _ @embed(file=/input.yaml)

nonexist: _ @embed(file=y/test.json, type=text)

dir: _ @embed(glob="x", type=yaml)

dirslash: _ @embed(glob="x/", type=yaml)

dotdotglob: _ @embed(glob="../test.json", type=yaml)

absglob: _ @embed(glob="/x/*.*", type=yaml)

doublestar: _ @embed(glob="**/*.json")

stream: _ @embed(file=test.ndjson)

singlestream: _ @embed(file=single.ndjson)

yamlstream: _ @embed(file=stream.yaml)

textproto: _ @embed(file=test.textproto)

norm1: _ @embed(file=./test.json)

norm2: _ @embed(file="x/../test.json")

norm3: _ @embed(file="x/../x/test.json")

norm4: _ @embed(file="x//test.json")

noTranslateBS: _ @embed(file="x\\test.json")

autoCUEfiletype: _ @embed(file="x.cue")
explicitCUEfiletype: _ @embed(file=xcue, type=cue)

// intentional missing type arg
unspecifiedFiletype1: _ @embed(glob=x/*.*)
unspecifiedFiletype2: _ @embed(glob=x/*)
unspecifiedFiletype3: _ @embed(glob=x/*.?son)
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.ndjson --
{ "x": 35 }
{ "x": 36 }
-- single.ndjson --
{ "x": 37 }
-- stream.yaml --
1
---
2
-- input.yaml --
a1: 2

-- x/test.json --
{ "x": 34 }
-- x/input.yaml --
a1: 2
-- test.textproto --
a: 1
-- x.cue --
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/err --
@embed: attribute must have file or glob field:
    ./test.cue:5:8
@embed: attribute cannot have both file and glob field:
    ./test.cue:7:9
@embed: cannot refer to parent directory:
    ./test.cue:9:11
@embed: only relative files are allowed:
    ./test.cue:11:8
@embed: open y/test.json: no such file or directory:
    ./test.cue:13:13
@embed: path not normalized, use "x" instead:
    ./test.cue:17:13
@embed: cannot refer to parent directory:
    ./test.cue:19:15
@embed: only relative files are allowed:
    ./test.cue:21:12
@embed: invalid glob pattern "**/*.json": '**' is not supported in patterns as of yet:
    ./test.cue:23:15
@embed: streaming not implemented: found more than one value in file:
    ./test.cue:25:11
@embed: encoding "jsonl" not (yet) supported: requires support for streaming:
    ./test.cue:27:17
@embed: streaming not implemented: found more than one value in file:
    ./test.cue:29:15
@embed: encoding "textproto" not (yet) supported: requires support for schema-guided decoding:
    ./test.cue:31:14
@embed: path not normalized, use "test.json" instead:
    ./test.cue:33:10
@embed: path not normalized, use "test.json" instead:
    ./test.cue:35:10
@embed: path not normalized, use "x/test.json" instead:
    ./test.cue:37:10
@embed: path not normalized, use "x/test.json" instead:
    ./test.cue:39:10
@embed: open x\test.json: no such file or directory:
    ./test.cue:41:18
@embed: encoding "cue" not (yet) supported:
    ./test.cue:43:20
@embed: encoding "cue" not (yet) supported:
    ./test.cue:44:24
@embed: extension not fully specified; type argument required:
    ./test.cue:47:25
@embed: extension not fully specified; type argument required:
    ./test.cue:48:25
@embed: extension not fully specified; type argument required:
    ./test.cue:49:25
@embed: extension not fully specified; type argument required:
    ./test.cue:50:25
@embed: cannot embed file "a/b/foo.json": in different module:
    ./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")

fileSymlinkDir: _ @embed(file=symlink-dir/test.json)

globSymlinkDir: _ @embed(glob="symlink-dir/*.json")
-- symlink/test.json --
{ "x": "symlink target file" }
-- symlink/y/test.json --
{ "y": "another 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"
    }
}
fileSymlinkDir: {
    y: "another symlink target file"
}
globSymlinkDir: {
    "symlink-dir/test.json": {
        y: "another symlink target file"
    }
}
