Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

59 lines
1.9 KiB
Go

package lsp
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
// TestOmniSharpSpec_HasCSharpLsAlternative pins the registry wiring: the C#
// server spec still serves csharp and now offers csharp-ls (a Roslyn stdio
// LSP that is far more commonly installed than OmniSharp) as an alternative
// command.
func TestOmniSharpSpec_HasCSharpLsAlternative(t *testing.T) {
spec := SpecByName("omnisharp")
require.NotNil(t, spec, "omnisharp spec must exist")
servesCS := false
for _, l := range spec.Languages {
if l == "csharp" {
servesCS = true
}
}
require.True(t, servesCS, "omnisharp spec must still list csharp")
hasAlt := false
for _, alt := range spec.AlternativeCommands {
if alt.Command == "csharp-ls" {
hasAlt = true
}
}
require.True(t, hasAlt, "omnisharp spec must offer csharp-ls as an alternative")
}
// TestProviderFromSpec_ResolvesCSharpLsAlternative verifies that when omnisharp
// is not on PATH but csharp-ls is, NewProviderFromSpec resolves to csharp-ls —
// and the resulting Provider still reports servesCSharp() == true, so the
// C#-scoped hardening (pre-restore, NU19xx advisory-diagnostic filter,
// MSBuild-wedge timeout) applies to the alternative unchanged.
func TestProviderFromSpec_ResolvesCSharpLsAlternative(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("PATH exec-bit faking is POSIX-only")
}
dir := t.TempDir()
// A fake csharp-ls on PATH; omnisharp is absent because PATH is only dir.
require.NoError(t, os.WriteFile(filepath.Join(dir, "csharp-ls"), []byte("#!/bin/sh\n"), 0o755))
t.Setenv("PATH", dir)
p := NewProviderFromSpec(SpecByName("omnisharp"), zap.NewNop())
require.NotNil(t, p)
assert.Equal(t, "csharp-ls", p.command, "alt command should win when omnisharp is off PATH")
assert.True(t, p.servesCSharp(), "a csharp-ls-constructed provider still serves C#")
assert.Contains(t, p.Languages(), "csharp")
}