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