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