Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/load: restore the error result on an empty string argument
TestEmptyImport was added a long time ago to ensure that calling load.Instances with an input of []string{""} would result in an error. Calling load.Instances with no arguments like `[]string{}` is fine, as it is an alias for the common case of `[]string{"."}`, much like `cue export` is an alias for `cue export .`. However, `cue export ""` should fail, as it's not a valid package pattern nor is it a valid file or directory name. As part of the early refactors of cue/load for modules support in https://cuelang.org/cl/548987 we rewrote this test to use internal APIs. As such, it actually stopped testing what it was meant to test, and cue/load silently started treating `[]string{}` as `[]string{"."}`. The cleanest solution appears to be in cleanPatterns; it never makes any sense to "clean" an empty pattern as the dot pattern. cleanPatterns already replaces an empty list with a dot pattern, which is the only case where we want to alias to the dot pattern. TestEmptyImport is also tweaked to use a testdata directory with a known CUE package inside a CUE module to double check that we fail even when the dot pattern would match a valid CUE package. Otherwise the empty Config.Dir results in using the current directory. While here, also rewrite getInst to no longer use internal APIs. It's really just a wrapper over load.Instances which expects a single instance to be returned. All else it did was to simplify passing a cwd and checking the resulting instance's error. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I0af58e59bb75b8046ec83f4b5cae57c28b138bde Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194410 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information