this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: add testscripts for backwards and forwards module compatibility

That is, sanity checking whether downstream consumption (`cue export`,
loading as a dependency) and upstream development (`cue mod tidy`,
`cue mod publish`) work with modules created or developed with either
older or newer versions of CUE.

A number of TODOs are left for areas where we know we need to improve.
This test aims to reflect all edge cases and the current behavior,
and so that future improvement can be seen with changes to these tests.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I82cf6418779bdf1bf53c05ab35ab0278ef24dd87
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195783
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+195
+139
cmd/cue/cmd/testdata/script/module_compatibility_backwards.txtar
··· 1 + # This test checks for backwards compatibility with modules developed 2 + # using older versions of CUE. It checks that: 3 + # 4 + # 1) Downstream consumption does work, where one only needs to load CUE packages. 5 + # `cue export`, loading as a dependency via `cue/load`, etc. 6 + # 2) Upstream development does work, where one may need to modify cue.mod/module.cue 7 + # or publish the module to a registry. `cue mod tidy`, `cue mod publish`, etc. 8 + # 9 + # TODO(mvdan): once we split up language.version from the schema version, 10 + # cover scenarios where just one of them is older. 11 + 12 + # This test uses an in-memory registry for `cue mod publish` to be able to succeed, 13 + # but some tests will also need ORIG_CUE_REGISTRY to fetch modules from _registry/ below. 14 + memregistry MEMREGISTRY 15 + env ORIG_CUE_REGISTRY=${CUE_REGISTRY} 16 + env CUE_REGISTRY=$MEMREGISTRY+insecure 17 + 18 + # A module that was created before the modules experiment, 19 + # without a major version suffix nor a language version. 20 + 21 + # Downstream consumption via cue.mod/*/ works. 22 + # Downstream consumption via a registry is not possible as its module path lacks a major version suffix. 23 + cd ${WORK}/premodules 24 + exec cue export 25 + stdout '"downstream": "hello from premodules.example"' 26 + 27 + # Continue inside the module's own directory as if we had cloned it directly. 28 + cd ${WORK} 29 + mv premodules/cue.mod/pkg/premodules.example premodules-downstream-direct 30 + cd premodules-downstream-direct 31 + 32 + # Downstream consumption via `cue export` fails; when the current module lacks 33 + # a language.version field, we always nudge the user or developer to add one. 34 + ! exec cue export 35 + stderr '^no language version declared in module.cue$' 36 + 37 + # Upstream development works once `cue mod fix` adds a language.version field. 38 + # TODO(mvdan): we don't have anything like `cue mod edit -langversion` if the user wants an older version. 39 + ! exec cue mod tidy --check 40 + stderr '^no language version declared in module.cue$' 41 + ! exec cue mod get some.dependency 42 + stderr '^no language version declared in module.cue$' 43 + ! exec cue mod publish v0.0.2 44 + stderr '^no language version declared in module.cue$' 45 + exec cue mod fix 46 + cmp cue.mod/module.cue ${WORK}/premodules-module.cue.fixed 47 + exec cue export 48 + stdout '"hello from premodules.example"' 49 + exec cue mod tidy --check 50 + 51 + # Upstream publishing then works once a source.kind is chosen by the user. 52 + ! exec cue mod publish v0.0.2 53 + stderr '^no source field found in cue.mod/module.cue$' 54 + exec cue mod edit --source self 55 + exec cue mod publish v0.0.2 56 + 57 + 58 + # A module that was created with a language.version of v0.8.0. 59 + 60 + # Downstream consumption via a registry works. 61 + # Note that we need to point CUE_REGISTRY back to the contents inside _registry/ below. 62 + env CUE_REGISTRY=${ORIG_CUE_REGISTRY} 63 + cd ${WORK}/v0.8.0-downstream-deps 64 + exec cue export 65 + stdout '"downstream": "hello from v0.8.0.example"' 66 + env CUE_REGISTRY=$MEMREGISTRY+insecure 67 + 68 + # Downstream consumption via cue.mod/*/ works. 69 + cd ${WORK}/v0.8.0-downstream-cuemod 70 + mv ${WORK}/_registry/v0.8.0.example_v0.0.1 cue.mod/pkg/v0.8.0.example 71 + exec cue export 72 + stdout '"downstream": "hello from v0.8.0.example"' 73 + 74 + # Continue inside the module's own directory as if we had cloned it directly. 75 + cd ${WORK} 76 + mv v0.8.0-downstream-cuemod/cue.mod/pkg/v0.8.0.example v0.8.0-downstream-direct 77 + cd v0.8.0-downstream-direct 78 + 79 + # Downstream consumption via `cue export` works. 80 + exec cue export 81 + stdout '"hello from v0.8.0.example"' 82 + 83 + # Upstream development via `cue mod tidy` works. 84 + exec cue mod tidy --check 85 + 86 + # Upstream publishing works directly, as v0.8.0 has no source.kind. 87 + exec cue mod publish v0.0.2 88 + 89 + 90 + -- premodules/cue.mod/module.cue -- 91 + module: "downstream.example" 92 + language: version: "v0.9.0" 93 + -- premodules/downstream.cue -- 94 + package downstream 95 + import "premodules.example:root" 96 + downstream: root 97 + -- premodules/cue.mod/pkg/premodules.example/cue.mod/module.cue -- 98 + module: "premodules.example" 99 + -- premodules-module.cue.fixed -- 100 + module: "premodules.example@v0" 101 + language: { 102 + version: "v0.9.0" 103 + } 104 + -- premodules/cue.mod/pkg/premodules.example/root.cue -- 105 + package root 106 + import "premodules.example/subpkg" 107 + subpkg 108 + -- premodules/cue.mod/pkg/premodules.example/subpkg/subpkg.cue -- 109 + package subpkg 110 + "hello from premodules.example" 111 + 112 + -- v0.8.0-downstream-deps/cue.mod/module.cue -- 113 + module: "downstream.example" 114 + language: version: "v0.9.0" 115 + deps: "v0.8.0.example": v: "v0.0.1" 116 + -- v0.8.0-downstream-deps/downstream.cue -- 117 + package downstream 118 + import "v0.8.0.example:root" 119 + downstream: root 120 + 121 + -- v0.8.0-downstream-cuemod/cue.mod/module.cue -- 122 + module: "downstream.example" 123 + language: version: "v0.9.0" 124 + -- v0.8.0-downstream-cuemod/cue.mod/pkg/.mkdir -- 125 + -- v0.8.0-downstream-cuemod/downstream.cue -- 126 + package downstream 127 + import "v0.8.0.example:root" 128 + downstream: root 129 + 130 + -- _registry/v0.8.0.example_v0.0.1/cue.mod/module.cue -- 131 + module: "v0.8.0.example@v0" 132 + language: version: "v0.8.0" 133 + -- _registry/v0.8.0.example_v0.0.1/root.cue -- 134 + package root 135 + import "v0.8.0.example/subpkg" 136 + subpkg 137 + -- _registry/v0.8.0.example_v0.0.1/subpkg/subpkg.cue -- 138 + package subpkg 139 + "hello from v0.8.0.example"
+56
cmd/cue/cmd/testdata/script/module_compatibility_forwards.txtar
··· 1 + # This test checks for forwards compatibility with modules developed 2 + # using newer versions of CUE. It checks that: 3 + # 4 + # 1) Downstream consumption does not work, as we don't support the newer language spec version. 5 + # 2) Upstream development does not work, as modifying cue.mod/module.cue or publishing 6 + # the module is not safe when we don't have or understand the schema it uses. 7 + # 8 + # TODO(mvdan): once we split up language.version from the schema version, 9 + # cover scenarios where just one of them is too new, 10 + # as we should allow downstream consumption when only the module schema version is too new. 11 + 12 + # A module that was created with a language.version of v0.99.0 in the far future. 13 + 14 + # TODO(mvdan): downstream consumption via cue.mod/*/ works when it should not, 15 + # because we do not yet use language.version as a minimum for parsing or evaluating CUE. 16 + cd ${WORK}/v0.99.0 17 + exec cue export 18 + stdout '"downstream": "hello from v0.99.0.example"' 19 + 20 + # TODO(mvdan): test downstream consumption via a registry; note that _registry/ complains 21 + # because it is unable to parse the module.cue file with a schema that is too new. 22 + 23 + # Continue inside the module's own directory as if we had cloned it directly. 24 + cd ${WORK} 25 + mv v0.99.0/cue.mod/pkg/v0.99.0.example v0.99.0-downstream-direct 26 + cd v0.99.0-downstream-direct 27 + 28 + # Downstream consumption via `cue export` does not work as we don't support the language spec version. 29 + ! exec cue export 30 + cmp stderr ${WORK}/v0.99.0-toonew.stderr 31 + 32 + # Upstream development and publishing is forbidden as we don't have or understand the schema. 33 + ! exec cue mod tidy --check 34 + cmp stderr ${WORK}/v0.99.0-toonew.stderr 35 + ! exec cue mod publish v0.0.2 36 + cmp stderr ${WORK}/v0.99.0-toonew.stderr 37 + 38 + -- v0.99.0-toonew.stderr -- 39 + language version "v0.99.0" declared in module.cue is too new for current language version "v0.9.0" 40 + -- v0.99.0/cue.mod/module.cue -- 41 + module: "downstream.example" 42 + language: version: "v0.9.0" 43 + -- v0.99.0/downstream.cue -- 44 + package downstream 45 + import "v0.99.0.example:root" 46 + downstream: root 47 + -- v0.99.0/cue.mod/pkg/v0.99.0.example/cue.mod/module.cue -- 48 + module: "v0.99.0.example" 49 + language: version: "v0.99.0" 50 + -- v0.99.0/cue.mod/pkg/v0.99.0.example/root.cue -- 51 + package root 52 + import "v0.99.0.example/subpkg" 53 + subpkg 54 + -- v0.99.0/cue.mod/pkg/v0.99.0.example/subpkg/subpkg.cue -- 55 + package subpkg 56 + "hello from v0.99.0.example"