From 268b661bd099d3824e0ecc58bb556a200fae4750 Mon Sep 17 00:00:00 2001 From: Jon Poole Date: Tue, 14 Nov 2023 13:48:35 +0000 Subject: [PATCH] core.HostFS() --- src/build/build_step_stress_test.go | 3 +- src/build/build_step_test.go | 6 ++-- src/core/config_test.go | 56 ++++++++++++++--------------- src/tool/tool_test.go | 5 ++- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/build/build_step_stress_test.go b/src/build/build_step_stress_test.go index c015bccdde..5b8a290cb3 100644 --- a/src/build/build_step_stress_test.go +++ b/src/build/build_step_stress_test.go @@ -6,7 +6,6 @@ package build_test import ( "fmt" "io" - "os" "testing" "github.com/stretchr/testify/assert" @@ -23,7 +22,7 @@ const size = 1000 var state *core.BuildState func TestBuildLotsOfTargets(t *testing.T) { - config, _ := core.ReadConfigFiles(os.DirFS("."), nil, nil) + config, _ := core.ReadConfigFiles(core.HostFS(), nil, nil) config.Please.NumThreads = 10 state = core.NewBuildState(config) state.Parser = &fakeParser{ diff --git a/src/build/build_step_test.go b/src/build/build_step_test.go index 487a450dc8..fd6736acdb 100644 --- a/src/build/build_step_test.go +++ b/src/build/build_step_test.go @@ -519,7 +519,7 @@ func TestSha1SingleHash(t *testing.T) { } func newStateWithHashCheckers(label, hashFunction string, hashCheckers ...string) (*core.BuildState, *core.BuildTarget) { - config, _ := core.ReadConfigFiles(os.DirFS("."), nil, nil) + config, _ := core.ReadConfigFiles(core.HostFS(), nil, nil) if hashFunction != "" { config.Build.HashFunction = hashFunction } @@ -538,7 +538,7 @@ func newStateWithHashCheckers(label, hashFunction string, hashCheckers ...string } func newStateWithHashFunc(label, hashFunc string) (*core.BuildState, *core.BuildTarget) { - config, _ := core.ReadConfigFiles(os.DirFS("."), nil, nil) + config, _ := core.ReadConfigFiles(core.HostFS(), nil, nil) config.Build.HashFunction = hashFunc state := core.NewBuildState(config) state.Config.Parse.BuildFileName = []string{"BUILD_FILE"} @@ -552,7 +552,7 @@ func newStateWithHashFunc(label, hashFunc string) (*core.BuildState, *core.Build } func newState(label string) (*core.BuildState, *core.BuildTarget) { - config, _ := core.ReadConfigFiles(os.DirFS("."), nil, nil) + config, _ := core.ReadConfigFiles(core.HostFS(), nil, nil) state := core.NewBuildState(config) state.Config.Parse.BuildFileName = []string{"BUILD_FILE"} target := core.NewBuildTarget(core.ParseBuildLabel(label, "")) diff --git a/src/core/config_test.go b/src/core/config_test.go index ba57a11a55..9f5316e2b4 100644 --- a/src/core/config_test.go +++ b/src/core/config_test.go @@ -15,11 +15,9 @@ import ( "github.com/thought-machine/please/src/cli" ) -var wdFS = os.DirFS(".") - func TestPlzConfigWorking(t *testing.T) { RepoRoot = "/repo/root" - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/working.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/working.plzconfig"}, nil) assert.NoError(t, err) assert.Equal(t, "pexmabob", config.Python.PexTool) @@ -33,12 +31,12 @@ func TestPlzConfigWorking(t *testing.T) { } func TestPlzConfigFailing(t *testing.T) { - _, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/failing.plzconfig"}, nil) + _, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/failing.plzconfig"}, nil) assert.Error(t, err) } func TestPlzConfigProfile(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/working.plzconfig"}, []string{"dev"}) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/working.plzconfig"}, []string{"dev"}) assert.NoError(t, err) assert.Equal(t, "pexmabob", config.Python.PexTool) assert.Equal(t, "/opt/java/bin/javac", config.Java.JavacTool) @@ -48,7 +46,7 @@ func TestPlzConfigProfile(t *testing.T) { } func TestMultiplePlzConfigFiles(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{ + config, err := ReadConfigFiles(HostFS(), []string{ "src/core/test_data/working.plzconfig", "src/core/test_data/failing.plzconfig", }, nil) @@ -58,7 +56,7 @@ func TestMultiplePlzConfigFiles(t *testing.T) { } func TestConfigSlicesOverwrite(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/slices.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/slices.plzconfig"}, nil) assert.NoError(t, err) // This should be completely overwritten by the config file assert.Equal(t, []string{"/sbin"}, config.Build.Path) @@ -177,29 +175,29 @@ func TestPleaseTildeLocationOverride(t *testing.T) { } func TestReadSemver(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/version_good.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/version_good.plzconfig"}, nil) assert.NoError(t, err) assert.EqualValues(t, 2, config.Please.Version.Major) assert.EqualValues(t, 3, config.Please.Version.Minor) assert.EqualValues(t, 4, config.Please.Version.Patch) - _, err = ReadConfigFiles(wdFS, []string{"src/core/test_data/version_bad.plzconfig"}, nil) + _, err = ReadConfigFiles(HostFS(), []string{"src/core/test_data/version_bad.plzconfig"}, nil) assert.Error(t, err) } func TestReadDurations(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/duration_good.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/duration_good.plzconfig"}, nil) assert.NoError(t, err) assert.EqualValues(t, 500*time.Millisecond, config.Build.Timeout) assert.EqualValues(t, 5*time.Second, config.Test.Timeout) - _, err = ReadConfigFiles(wdFS, []string{"src/core/test_data/duration_bad.plzconfig"}, nil) + _, err = ReadConfigFiles(HostFS(), []string{"src/core/test_data/duration_bad.plzconfig"}, nil) assert.Error(t, err) } func TestReadByteSizes(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/bytesize_good.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/bytesize_good.plzconfig"}, nil) assert.NoError(t, err) assert.EqualValues(t, 500*1000*1000, config.Cache.DirCacheHighWaterMark) - _, err = ReadConfigFiles(wdFS, []string{"src/core/test_data/bytesize_bad.plzconfig"}, nil) + _, err = ReadConfigFiles(HostFS(), []string{"src/core/test_data/bytesize_bad.plzconfig"}, nil) assert.Error(t, err) } @@ -212,29 +210,29 @@ func TestCompletions(t *testing.T) { } func TestConfigVerifiesOptions(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/testrunner_good.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/testrunner_good.plzconfig"}, nil) assert.NoError(t, err) assert.Equal(t, "pytest", config.Python.TestRunner) - _, err = ReadConfigFiles(wdFS, []string{"src/core/test_data/testrunner_bad.plzconfig"}, nil) + _, err = ReadConfigFiles(HostFS(), []string{"src/core/test_data/testrunner_bad.plzconfig"}, nil) assert.Error(t, err) } func TestDefaultHashCheckers(t *testing.T) { - config, err := ReadConfigFiles(wdFS, nil, nil) + config, err := ReadConfigFiles(HostFS(), nil, nil) assert.NoError(t, err) assert.ElementsMatch(t, []string{"sha1", "sha256", "blake3"}, config.Build.HashCheckers) } func TestHashCheckersConfig(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/hashcheckers.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/hashcheckers.plzconfig"}, nil) assert.NoError(t, err) assert.ElementsMatch(t, []string{"blake3"}, config.Build.HashCheckers) } func TestOverrideHashCheckersConfig(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/hashcheckers.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/hashcheckers.plzconfig"}, nil) assert.NoError(t, err) err = config.ApplyOverrides(map[string]string{"build.hashcheckers": "sha256"}) @@ -243,7 +241,7 @@ func TestOverrideHashCheckersConfig(t *testing.T) { } func TestOverrideHashCheckersNoConfig(t *testing.T) { - config, err := ReadConfigFiles(wdFS, nil, nil) + config, err := ReadConfigFiles(HostFS(), nil, nil) assert.NoError(t, err) err = config.ApplyOverrides(map[string]string{"build.hashcheckers": "sha1,blake3"}) @@ -252,7 +250,7 @@ func TestOverrideHashCheckersNoConfig(t *testing.T) { } func TestUnknownHashChecker(t *testing.T) { - config, err := ReadConfigFiles(wdFS, nil, nil) + config, err := ReadConfigFiles(HostFS(), nil, nil) assert.NoError(t, err) err = config.ApplyOverrides(map[string]string{"build.hashcheckers": "fake-algo"}) @@ -260,7 +258,7 @@ func TestUnknownHashChecker(t *testing.T) { } func TestBuildEnvSection(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/buildenv.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/buildenv.plzconfig"}, nil) assert.NoError(t, err) expected := []string{ "BAR_BAR=first", @@ -273,7 +271,7 @@ func TestBuildEnvSection(t *testing.T) { func TestPassEnv(t *testing.T) { t.Setenv("FOO", "first") t.Setenv("BAR", "second") - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/passenv.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/passenv.plzconfig"}, nil) assert.NoError(t, err) expected := []string{ "BAR=second", @@ -286,7 +284,7 @@ func TestPassEnv(t *testing.T) { func TestPassUnsafeEnv(t *testing.T) { t.Setenv("FOO", "first") t.Setenv("BAR", "second") - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/passunsafeenv.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/passunsafeenv.plzconfig"}, nil) assert.NoError(t, err) expected := []string{ "BAR=second", @@ -303,7 +301,7 @@ func TestPassUnsafeEnvExcludedFromHash(t *testing.T) { err = os.Unsetenv("BAR") require.NoError(t, err) - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/passunsafeenv.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/passunsafeenv.plzconfig"}, nil) require.NoError(t, err) expected := config.Hash() @@ -315,7 +313,7 @@ func TestPassUnsafeEnvExcludedFromHash(t *testing.T) { } func TestBuildPathWithPathEnv(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/passenv.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/passenv.plzconfig"}, nil) assert.NoError(t, err) assert.Equal(t, config.Build.Path, strings.Split(os.Getenv("PATH"), ":")) } @@ -350,7 +348,7 @@ func TestUpdateArgsWithQuotedAliases(t *testing.T) { } func TestParseNewFormatAliases(t *testing.T) { - c, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/alias.plzconfig"}, nil) + c, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/alias.plzconfig"}, nil) assert.NoError(t, err) assert.Equal(t, 2, len(c.Alias)) a := c.Alias["auth"] @@ -360,7 +358,7 @@ func TestParseNewFormatAliases(t *testing.T) { } func TestAttachAliasFlags(t *testing.T) { - c, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/alias.plzconfig"}, nil) + c, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/alias.plzconfig"}, nil) assert.NoError(t, err) t.Setenv("GO_FLAGS_COMPLETION", "1") p := flags.NewParser(&struct{}{}, 0) @@ -396,7 +394,7 @@ func TestAttachAliasFlags(t *testing.T) { } func TestPrintAliases(t *testing.T) { - c, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/alias.plzconfig"}, nil) + c, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/alias.plzconfig"}, nil) assert.NoError(t, err) var buf bytes.Buffer c.PrintAliases(&buf) @@ -438,7 +436,7 @@ func TestEnsurePleaseLocation(t *testing.T) { } func TestPluginConfig(t *testing.T) { - config, err := ReadConfigFiles(wdFS, []string{"src/core/test_data/plugin.plzconfig"}, nil) + config, err := ReadConfigFiles(HostFS(), []string{"src/core/test_data/plugin.plzconfig"}, nil) assert.NoError(t, err) assert.Equal(t, []string{"fooc"}, config.Plugin["foo"].ExtraValues["fooctool"]) } diff --git a/src/tool/tool_test.go b/src/tool/tool_test.go index 52afdb4277..1595e91fe7 100644 --- a/src/tool/tool_test.go +++ b/src/tool/tool_test.go @@ -1,7 +1,6 @@ package tool import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -10,7 +9,7 @@ import ( ) func TestMatchingTools(t *testing.T) { - c, err := core.ReadConfigFiles(os.DirFS("."), nil, nil) + c, err := core.ReadConfigFiles(core.HostFS(), nil, nil) assert.NoError(t, err) assert.Equal(t, map[string]string{"langserver": "//_please:build_langserver"}, matchingTools(c, "la")) assert.Equal(t, map[string]string{"langserver": "//_please:build_langserver"}, matchingTools(c, "lang")) @@ -20,7 +19,7 @@ func TestMatchingTools(t *testing.T) { } func TestAllToolNames(t *testing.T) { - c, err := core.ReadConfigFiles(os.DirFS("."), nil, nil) + c, err := core.ReadConfigFiles(core.HostFS(), nil, nil) assert.NoError(t, err) assert.Equal(t, []string{"javacworker"}, allToolNames(c, "ja")) }