diff --git a/console_test.go b/console_test.go new file mode 100644 index 0000000..60369f0 --- /dev/null +++ b/console_test.go @@ -0,0 +1,39 @@ +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") +} + +// 请根据需要定义更多的测试用例来覆盖函数的不同方面。