golang.org/x/tools/gopls@v0.15.3/internal/test/integration/modfile/tempmodfile_test.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package modfile
     6  
     7  import (
     8  	"testing"
     9  
    10  	. "golang.org/x/tools/gopls/internal/test/integration"
    11  )
    12  
    13  // This test replaces an older, problematic test (golang/go#57784). But it has
    14  // been a long time since the go command would mutate go.mod files.
    15  //
    16  // TODO(golang/go#61970): the tempModfile setting should be removed entirely.
    17  func TestTempModfileUnchanged(t *testing.T) {
    18  	// badMod has a go.mod file that is missing a go directive.
    19  	const badMod = `
    20  -- go.mod --
    21  module badmod.test/p
    22  -- p.go --
    23  package p
    24  `
    25  
    26  	WithOptions(
    27  		Modes(Default), // no reason to test this with a remote gopls
    28  		ProxyFiles(workspaceProxy),
    29  		Settings{
    30  			"tempModfile": true,
    31  		},
    32  	).Run(t, badMod, func(t *testing.T, env *Env) {
    33  		env.OpenFile("p.go")
    34  		env.AfterChange()
    35  		want := "module badmod.test/p\n"
    36  		got := env.ReadWorkspaceFile("go.mod")
    37  		if got != want {
    38  			t.Errorf("go.mod content:\n%s\nwant:\n%s", got, want)
    39  		}
    40  	})
    41  }