40 lines
807 B
Go
40 lines
807 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"os"
|
|
)
|
|
|
|
func TestExecInput(t *testing.T) {
|
|
// 设置测试环境变量
|
|
os.Setenv("HOME", "/fake/home")
|
|
|
|
// 定义测试用例
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantErr bool
|
|
}{
|
|
{"Help Command", "help", false},
|
|
{"CD with No Argument", "cd", false},
|
|
{"CD with Argument", "cd /tmp", false},
|
|
{"Set with Insufficient Args", "set", true},
|
|
// 添加更多测试用例...
|
|
}
|
|
|
|
// 执行测试用例
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := execInput(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("execInput() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
|
|
// 清除测试环境变量
|
|
os.Unsetenv("HOME")
|
|
}
|
|
|
|
// 请根据需要定义更多的测试用例来覆盖函数的不同方面。
|