Skip to content

Commit

Permalink
lsp: add simple workspace-based test for basic CUE module
Browse files Browse the repository at this point in the history
This is in preparation for later CLs which enforce that a workspace
folder must correspond to the root of a CUE module.

Also add a build constraint to prevent workspace folder tests running on
Windows. In a later CL this becomes relevant because a message shown to
the user includes a directory path. Fixing this is tracked by
https://cuelang.org/issue/2752.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Id3cad53160f4de6360c9d9866a2291dca567bc42
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206615
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
myitcv committed Jan 3, 2025
1 parent 9d9632a commit 5747d91
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/cue/cmd/integration/workspace/workspace_folders_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
//go:build !windows

package workspace

import (
"testing"

"cuelang.org/go/internal/golangorgx/gopls/hooks"
. "cuelang.org/go/internal/golangorgx/gopls/test/integration"
"cuelang.org/go/internal/golangorgx/gopls/test/integration/fake"
"github.com/go-quicktest/qt"
)

func TestMain(m *testing.M) {
Main(m, hooks.Options)
}

// TestWorkingSimpleModule ensures that we have a successful package load for a
// simple module rooted in the workspace folder with a single CUE file at the
// root.
func TestWorkingSimpleModule(t *testing.T) {
const files = `
-- cue.mod/module.cue --
module: "mod.example"
language: {
version: "v0.11.0"
}
-- a.cue --
package a
-- b/b.cue --
package c
`
WithOptions().Run(t, files, func(t *testing.T, env *Env) {
// Simulate a change and ensure we get diagnostics back
env.OpenFile("a.cue")
env.EditBuffer("a.cue", fake.NewEdit(1, 0, 1, 0, "\nx: 5\n"))
got := env.BufferText("a.cue")
want := "package a\n\nx: 5\n"
qt.Assert(t, qt.Equals(got, want))
env.Await(env.DoneWithChange())
})
}

// TestMultipleWorkspaceFolders verifies the behaviour of starting 'cue lsp'
// with multiple WorkspaceFolders. This is currently not supported, and hence
// the test is a negative test that asserts 'cue lsp' will fail (during the
Expand Down

0 comments on commit 5747d91

Please sign in to comment.