cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.09k stars 290 forks source link

cue/load: fails on absolute paths to directories #1908

Open verdverm opened 2 years ago

verdverm commented 2 years ago

What version of CUE are you using (cue version)?

v0.4.3

What did you do?

$ cue eval $(pwd)

What did you expect to see?

the same output as cue eval in the current directory

What did you see instead?

an error

cannot find package "/home/tony/hof/hof"  # or whatever the CWD is
mvdan commented 2 years ago

The problem seems to be that we end up using filepath.Join with the module root and the directory to be loaded, which does the wrong thing when that directory is absolute. Definitely needs a fix, but I also don't think this is urgent as most common scenarios have a workaround: using a relative path.

myitcv commented 2 years ago

For completeness here is a repro.

What did you do?

exec cue eval $WORK
cmp stdout stdout.golden

-- x.cue --
package x
x: 5
-- stdout.golden --
x: 5

What did you expect to see?

A passing test

What did you see instead?

> exec cue eval $WORK
[stderr]
cannot find package "$WORK"
[exit status 1]
FAIL: /tmp/testscript708032307/repro.txtar/script.txtar:1: unexpected command failure
myitcv commented 2 years ago

(sent too early)

Thanks for the report, @verdverm!

jeffmccune commented 8 months ago

Refer to https://github.com/cue-lang/cue/blob/v0.7.0/cue/load/import.go#L400

mvdan commented 5 months ago

I discovered the same bug recently and added a failing test case in https://review.gerrithub.io/c/cue-lang/cue/+/1194381. I will take a look at this soon.