2017-08-31 14:52:51 +00:00
|
|
|
package genautocomplete
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCompletionBash(t *testing.T) {
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_bash")
|
2017-08-31 14:52:51 +00:00
|
|
|
assert.NoError(t, err)
|
2020-10-10 21:16:21 +00:00
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
2017-08-31 14:52:51 +00:00
|
|
|
|
|
|
|
bashCommandDefinition.Run(bashCommandDefinition, []string{tempFile.Name()})
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
2017-08-31 14:52:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(bs))
|
|
|
|
}
|
|
|
|
|
2020-10-10 21:16:21 +00:00
|
|
|
func TestCompletionBashStdout(t *testing.T) {
|
|
|
|
originalStdout := os.Stdout
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
|
|
|
|
|
|
|
os.Stdout = tempFile
|
|
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
|
|
|
|
bashCommandDefinition.Run(bashCommandDefinition, []string{"-"})
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
output, err := os.ReadFile(tempFile.Name())
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(output))
|
|
|
|
}
|
|
|
|
|
2017-08-31 14:52:51 +00:00
|
|
|
func TestCompletionZsh(t *testing.T) {
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
2017-08-31 14:52:51 +00:00
|
|
|
assert.NoError(t, err)
|
2020-10-10 21:16:21 +00:00
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
2017-08-31 14:52:51 +00:00
|
|
|
|
|
|
|
zshCommandDefinition.Run(zshCommandDefinition, []string{tempFile.Name()})
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
2017-08-31 14:52:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(bs))
|
|
|
|
}
|
2020-04-28 16:53:20 +00:00
|
|
|
|
2020-10-10 21:16:21 +00:00
|
|
|
func TestCompletionZshStdout(t *testing.T) {
|
|
|
|
originalStdout := os.Stdout
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
|
|
|
|
|
|
|
os.Stdout = tempFile
|
|
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
|
|
|
|
zshCommandDefinition.Run(zshCommandDefinition, []string{"-"})
|
2022-08-20 14:38:02 +00:00
|
|
|
output, err := os.ReadFile(tempFile.Name())
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(output))
|
|
|
|
}
|
|
|
|
|
2020-04-28 16:53:20 +00:00
|
|
|
func TestCompletionFish(t *testing.T) {
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_fish")
|
2020-04-28 16:53:20 +00:00
|
|
|
assert.NoError(t, err)
|
2020-10-10 21:16:21 +00:00
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
2020-04-28 16:53:20 +00:00
|
|
|
|
|
|
|
fishCommandDefinition.Run(fishCommandDefinition, []string{tempFile.Name()})
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
2020-04-28 16:53:20 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(bs))
|
|
|
|
}
|
2020-10-10 21:16:21 +00:00
|
|
|
|
|
|
|
func TestCompletionFishStdout(t *testing.T) {
|
|
|
|
originalStdout := os.Stdout
|
2022-08-20 14:38:02 +00:00
|
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
_ = tempFile.Close()
|
|
|
|
_ = os.Remove(tempFile.Name())
|
|
|
|
}()
|
|
|
|
|
|
|
|
os.Stdout = tempFile
|
|
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
|
|
|
|
fishCommandDefinition.Run(fishCommandDefinition, []string{"-"})
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
output, err := os.ReadFile(tempFile.Name())
|
2020-10-10 21:16:21 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, string(output))
|
|
|
|
}
|