github.com/tiagovtristao/plz@v13.4.0+incompatible/src/run/run_test.go (about) 1 package run 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/thought-machine/please/src/core" 10 ) 11 12 func init() { 13 if err := os.Chdir("src/run/test_data"); err != nil { 14 panic(err) 15 } 16 } 17 18 func TestSequential(t *testing.T) { 19 state, labels1, labels2 := makeState() 20 code := Sequential(state, labels1, nil, true, false) 21 assert.Equal(t, 0, code) 22 code = Sequential(state, labels2, nil, false, false) 23 assert.Equal(t, 1, code) 24 } 25 26 func TestParallel(t *testing.T) { 27 state, labels1, labels2 := makeState() 28 code := Parallel(state, labels1, nil, 5, false, false) 29 assert.Equal(t, 0, code) 30 code = Parallel(state, labels2, nil, 5, true, false) 31 assert.Equal(t, 1, code) 32 } 33 34 func TestEnvVars(t *testing.T) { 35 os.Setenv("PATH", "/usr/local/bin:/usr/bin:/bin") 36 config := core.DefaultConfiguration() 37 config.Build.Path = []string{"/wibble"} 38 env := environ(config, false) 39 assert.Contains(t, env, "PATH=/usr/local/bin:/usr/bin:/bin") 40 assert.NotContains(t, env, "PATH=/wibble") 41 env = environ(config, true) 42 assert.NotContains(t, env, "PATH=/usr/local/bin:/usr/bin:/bin") 43 assert.Contains(t, env, "PATH="+os.Getenv("TMP_DIR")+"/.please:/wibble") 44 } 45 46 func makeState() (*core.BuildState, []core.BuildLabel, []core.BuildLabel) { 47 state := core.NewBuildState(1, nil, 0, core.DefaultConfiguration()) 48 target1 := core.NewBuildTarget(core.ParseBuildLabel("//:true", "")) 49 target1.IsBinary = true 50 target1.AddOutput("true") 51 state.Graph.AddTarget(target1) 52 target2 := core.NewBuildTarget(core.ParseBuildLabel("//:false", "")) 53 target2.IsBinary = true 54 target2.AddOutput("false") 55 state.Graph.AddTarget(target2) 56 return state, []core.BuildLabel{target1.Label}, []core.BuildLabel{target1.Label, target2.Label} 57 }