Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't initialize plugins and user settings in tests #3220

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func main() {
screen.TermMessage(err)
}

config.InitRuntimeFiles()
config.InitRuntimeFiles(true)
config.InitPlugins()

err = config.ReadSettings()
Expand Down
2 changes: 1 addition & 1 deletion cmd/micro/micro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func startup(args []string) (tcell.SimulationScreen, error) {
return nil, err
}

config.InitRuntimeFiles()
config.InitRuntimeFiles(true)
config.InitPlugins()

err = config.ReadSettings()
Expand Down
2 changes: 1 addition & 1 deletion internal/action/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func reloadRuntime(reloadPlugins bool) {
}
}

config.InitRuntimeFiles()
config.InitRuntimeFiles(true)

if reloadPlugins {
config.InitPlugins()
Expand Down
5 changes: 3 additions & 2 deletions internal/buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type operation struct {

func init() {
ulua.L = lua.NewState()
config.InitRuntimeFiles()
config.InitPlugins()
// TODO: uncomment InitRuntimeFiles once we fix races between syntax
// highlighting and buffer editing.
// config.InitRuntimeFiles(false)
config.InitGlobalSettings()
config.GlobalSettings["backup"] = false
config.GlobalSettings["fastdirty"] = true
Expand Down
2 changes: 1 addition & 1 deletion internal/buffer/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
} else if option == "statusline" {
screen.Redraw()
} else if option == "filetype" {
config.InitRuntimeFiles()
config.InitRuntimeFiles(true)
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
Expand Down
14 changes: 11 additions & 3 deletions internal/config/rtfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type RuntimeFile interface {
var allFiles [][]RuntimeFile
var realFiles [][]RuntimeFile

func init() {
initRuntimeVars()
}

func initRuntimeVars() {
allFiles = make([][]RuntimeFile, NumTypes)
realFiles = make([][]RuntimeFile, NumTypes)
Expand Down Expand Up @@ -166,10 +170,14 @@ func ListRealRuntimeFiles(fileType RTFiletype) []RuntimeFile {
return realFiles[fileType]
}

// InitRuntimeFiles initializes all assets file and the config directory
func InitRuntimeFiles() {
// InitRuntimeFiles initializes all assets files and the config directory.
// If `user` is false, InitRuntimeFiles ignores the config directory and
// initializes asset files only.
func InitRuntimeFiles(user bool) {
add := func(fileType RTFiletype, dir, pattern string) {
AddRuntimeFilesFromDirectory(fileType, filepath.Join(ConfigDir, dir), pattern)
if user {
AddRuntimeFilesFromDirectory(fileType, filepath.Join(ConfigDir, dir), pattern)
}
AddRuntimeFilesFromAssets(fileType, path.Join("runtime", dir), pattern)
}

Expand Down
3 changes: 1 addition & 2 deletions internal/config/rtfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func init() {
InitRuntimeFiles()
InitPlugins()
InitRuntimeFiles(false)
}

func TestAddFile(t *testing.T) {
Expand Down
Loading