github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/shells_int_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "runtime" 7 "testing" 8 9 "github.com/ActiveState/cli/internal/testhelpers/suite" 10 11 "github.com/ActiveState/cli/internal/constants" 12 "github.com/ActiveState/cli/internal/fileutils" 13 "github.com/ActiveState/cli/internal/testhelpers/e2e" 14 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 15 ) 16 17 type ShellsIntegrationTestSuite struct { 18 tagsuite.Suite 19 } 20 21 func (suite *ShellsIntegrationTestSuite) TestShells() { 22 suite.OnlyRunForTags(tagsuite.Critical, tagsuite.Shell) 23 24 ts := e2e.New(suite.T(), false) 25 defer ts.Close() 26 27 var shells []e2e.Shell 28 switch runtime.GOOS { 29 case "linux": 30 shells = []e2e.Shell{e2e.Bash, e2e.Fish, e2e.Tcsh, e2e.Zsh} 31 case "darwin": 32 shells = []e2e.Shell{e2e.Bash, e2e.Fish, e2e.Zsh, e2e.Tcsh} 33 case "windows": 34 shells = []e2e.Shell{e2e.Bash, e2e.Cmd} 35 } 36 37 // Checkout the first instance. It doesn't matter which shell is used. 38 cp := ts.SpawnWithOpts( 39 e2e.OptArgs("checkout", "ActiveState-CLI/small-python"), 40 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 41 ) 42 cp.Expect("Checked out project", e2e.RuntimeSourcingTimeoutOpt) 43 cp.ExpectExitCode(0) 44 45 for _, shell := range shells { 46 suite.T().Run(fmt.Sprintf("using_%s", shell), func(t *testing.T) { 47 ts.SetT(t) 48 49 if shell == e2e.Zsh { 50 err := fileutils.Touch(filepath.Join(ts.Dirs.HomeDir, ".zshrc")) 51 suite.Require().NoError(err) 52 } 53 54 // Run the checkout in a particular shell. 55 cp = ts.SpawnShellWithOpts(shell) 56 cp.SendLine(e2e.QuoteCommand(shell, ts.ExecutablePath(), "checkout", "ActiveState-CLI/small-python", string(shell))) 57 cp.Expect("Checked out project") 58 cp.SendLine("exit") 59 if shell != e2e.Cmd { 60 cp.ExpectExitCode(0) 61 } 62 63 // There are 2 or more instances checked out, so we should get a prompt in whichever shell we 64 // use. 65 cp = ts.SpawnShellWithOpts(shell, e2e.OptAppendEnv(constants.DisableRuntime+"=false")) 66 cp.SendLine(e2e.QuoteCommand(shell, ts.ExecutablePath(), "shell", "small-python")) 67 cp.Expect("Multiple project paths") 68 69 // Just pick the first one and verify the selection prompt works. 70 cp.SendEnter() 71 cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt) 72 73 // Verify that the command prompt contains the right info, except for tcsh, whose prompt does 74 // not behave like other shells'. 75 if shell != e2e.Tcsh { 76 cp.Expect("[ActiveState-CLI/small-python]") 77 } 78 79 // Verify the runtime is functioning properly. 80 cp.SendLine("python3 --version") 81 cp.Expect("Python 3.10") 82 83 // Verify the expected shell is running. 84 switch shell { 85 case e2e.Cmd: 86 cp.SendLine("echo %COMSPEC%") 87 cp.Expect(string(shell)) 88 case e2e.Fish: 89 cp.SendLine("echo $fish_pid") 90 cp.ExpectRe("\\d+") 91 default: 92 cp.SendLine("echo $0") 93 cp.Expect(string(shell)) 94 } 95 96 // Verify exiting the shell works. 97 cp.SendLine("exit") 98 cp.Expect("Deactivated") 99 100 // Exit the spawned shell. 101 cp.SendLine("exit") 102 cp.ExpectExitCode(0) 103 }) 104 } 105 } 106 107 func TestShellsIntegrationTestSuite(t *testing.T) { 108 suite.Run(t, new(ShellsIntegrationTestSuite)) 109 }