github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/sys/sys_test.go (about)

     1  package sys
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
    12  )
    13  
    14  func TestArgv(t *testing.T) {
    15  	f := NewFixture(t)
    16  	f.File("Tiltfile", `
    17  print(sys.argv)
    18  `)
    19  
    20  	quoted := []string{}
    21  	for _, arg := range os.Args {
    22  		quoted = append(quoted, fmt.Sprintf("%q", arg))
    23  	}
    24  	expected := fmt.Sprintf("[%s]\n", strings.Join(quoted, ", "))
    25  
    26  	_, err := f.ExecFile("Tiltfile")
    27  	assert.NoError(t, err)
    28  	assert.Equal(t, expected, f.PrintOutput())
    29  }
    30  
    31  func TestExecutable(t *testing.T) {
    32  	f := NewFixture(t)
    33  	f.File("Tiltfile", `
    34  print(sys.executable)
    35  `)
    36  
    37  	expected, _ := os.Executable()
    38  	_, err := f.ExecFile("Tiltfile")
    39  	assert.NoError(t, err)
    40  	assert.Equal(t, fmt.Sprintf("%v\n", expected), f.PrintOutput())
    41  }
    42  
    43  func NewFixture(tb testing.TB) *starkit.Fixture {
    44  	return starkit.NewFixture(tb, NewPlugin())
    45  }