# mixing two anonymous packages
exec cue eval t.cue data.cue
cmp stdout stdout-t

# allow mixing named with anonymous package in files mode
exec cue eval kube.cue data.cue
cmp stdout stdout-files

# allow mixing named with anonymous package in files mode
exec cue eval kube.cue data.cue t.cue
cmp stdout stdout-files

# don't pick up the unnamed package in directory mode
exec cue eval .
cmp stdout stdout-pkg

# don't allow mixing two differently named packages
! exec cue eval kube.cue foo/kube2.cue
cmp stderr different-packages.stderr

# When passing multiple CUE files in different directories,
# cue/load will sort the filenames so that children come later.
# Due to a bug, we had an unstable sort that changed between Go 1.18 and 1.19.
# Ensure that our sorting is deterministic with 8 scattered files.
cd sort

# First, test with the same input order that "find" would use: lexically sorted.
exec cue eval print.cue root_1.cue root_2/child_1.cue root_2/child_2.cue root_2/child_3.cue root_2/child_4/grandchild_1.cue root_2/child_4/grandchild_2.cue root_2/child_5.cue root_2/child_6.cue root_2/child_7.cue root_3.cue
cmp stdout stdout-sort

# Second, test with the opposite order of what we want.
exec cue eval print.cue root_2/child_4/grandchild_2.cue root_2/child_4/grandchild_1.cue root_2/child_7.cue root_2/child_6.cue root_2/child_5.cue root_2/child_3.cue root_2/child_2.cue root_2/child_1.cue root_3.cue root_1.cue
cmp stdout stdout-sort

cd ..

-- different-packages.stderr --
found packages "kube" (kube.cue) and "kube2" (kube2.cue) in "."
-- data.cue --
foo:3
-- t.cue --
foo: int
bar: 3
-- kube.cue --
package kube

foo: int
bar: 3
-- foo/kube2.cue --
package kube2

foo: int
bar: 3
-- stdout-t --
foo: 3
bar: 3
-- stdout-files --
foo: 3
bar: 3
-- stdout-pkg --
foo: int
bar: 3
-- sort/print.cue --
files: {}
flat: [for k, _ in files {k}]
-- sort/root_1.cue --
files: root_1: 0
-- sort/root_2/child_1.cue --
files: child_1: 0
-- sort/root_2/child_2.cue --
files: child_2: 0
-- sort/root_2/child_3.cue --
files: child_3: 0
-- sort/root_2/child_4/grandchild_1.cue --
files: grandchild_1: 0
-- sort/root_2/child_4/grandchild_2.cue --
files: grandchild_2: 0
-- sort/root_2/child_5.cue --
files: child_5: 0
-- sort/root_2/child_6.cue --
files: child_6: 0
-- sort/root_2/child_7.cue --
files: child_7: 0
-- sort/root_3.cue --
files: root_3: 0
-- sort/stdout-sort --
files: {
    child_1:      0
    child_2:      0
    child_3:      0
    child_5:      0
    child_6:      0
    child_7:      0
    grandchild_1: 0
    grandchild_2: 0
    root_1:       0
    root_3:       0
}
flat: ["root_1", "root_3", "child_1", "child_2", "child_3", "child_5", "child_6", "child_7", "grandchild_1", "grandchild_2"]
