exec cue mod edit --source self
cmp cue.mod/module.cue want-module-0

exec cue mod edit --source git
cmp cue.mod/module.cue want-module-1

exec cue mod edit --drop-source
cmp cue.mod/module.cue want-module-2

exec cue mod edit --require foo.bar@v0.2.3
cmp cue.mod/module.cue want-module-3

! exec cue mod edit --require bad-module!
cmp stderr want-stderr

exec cue mod edit --drop-require foo.bar@v0
cmp cue.mod/module.cue want-module-4

exec cue mod edit --module othermain.org@v1
cmp cue.mod/module.cue want-module-5

# Set specific version.
exec cue mod edit --language-version v0.9.2
cmp cue.mod/module.cue want-module-6

# Set latest version.
exec cue mod edit --language-version current
cmpenv cue.mod/module.cue want-module-7

# Set version earlier than earliest module schema version.
! exec cue mod edit --language-version v0.4.3
cmp stderr want-stderr-8

# Set version too new.
! exec cue mod edit --language-version v2.3.4
cmpenv stderr want-stderr-9

# Check that it's an error to set the version earlier than
# allowed by some of the fields already present.
exec cue mod edit --source self
! exec cue mod edit --language-version v0.8.0
cmp stderr want-stderr-10

-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.9.0-alpha.0"
-- want-module-0 --
module: "main.org@v0"
language: {
	version: "v0.9.0-alpha.0"
}
source: {
	kind: "self"
}
-- want-module-1 --
module: "main.org@v0"
language: {
	version: "v0.9.0-alpha.0"
}
source: {
	kind: "git"
}
-- want-module-2 --
module: "main.org@v0"
language: {
	version: "v0.9.0-alpha.0"
}
-- want-module-3 --
module: "main.org@v0"
language: {
	version: "v0.9.0-alpha.0"
}
deps: {
	"foo.bar@v0": {
		v: "v0.2.3"
	}
}
-- want-stderr --
invalid argument "bad-module!" for "--require" flag: invalid module path@version "bad-module!"
-- want-module-4 --
module: "main.org@v0"
language: {
	version: "v0.9.0-alpha.0"
}
-- want-module-5 --
module: "othermain.org@v1"
language: {
	version: "v0.9.0-alpha.0"
}
-- want-module-6 --
module: "othermain.org@v1"
language: {
	version: "v0.9.2"
}
-- want-module-7 --
module: "othermain.org@v1"
language: {
	version: "$CUE_LANGUAGE_VERSION"
}
-- want-stderr-8 --
invalid argument "v0.4.3" for "--language-version" flag: language version "v0.4.3" is too early for module.cue schema (earliest allowed is v0.8.0-alpha.0)
-- want-stderr-9 --
invalid argument "v2.3.4" for "--language-version" flag: language version "v2.3.4" may not be after current language version $CUE_LANGUAGE_VERSION
-- want-stderr-10 --
invalid resulting module.cue file after edits: cannot parse result: invalid module.cue file: source field is not allowed at this language version; need at least v0.9.0-alpha.0
