Skip to content

Commit

Permalink
core.HostFS()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatskaari committed Nov 14, 2023
1 parent 896fa06 commit 268b661
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/build/build_step_stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package build_test
import (
"fmt"
"io"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions src/build/build_step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"}
Expand All @@ -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, ""))
Expand Down
56 changes: 27 additions & 29 deletions src/core/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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"})
Expand All @@ -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"})
Expand All @@ -252,15 +250,15 @@ 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"})
assert.Error(t, err)
}

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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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()
Expand All @@ -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"), ":"))
}
Expand Down Expand Up @@ -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"]
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"])
}
5 changes: 2 additions & 3 deletions src/tool/tool_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tool

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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"))
Expand All @@ -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"))
}

0 comments on commit 268b661

Please sign in to comment.