summaryrefslogtreecommitdiff
path: root/cmds/cmds_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/cmds_test.go')
-rw-r--r--cmds/cmds_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/cmds/cmds_test.go b/cmds/cmds_test.go
new file mode 100644
index 0000000..d59093a
--- /dev/null
+++ b/cmds/cmds_test.go
@@ -0,0 +1,58 @@
+package cmds
+
+import (
+ "os"
+ "testing"
+)
+
+func TestCd(t *testing.T) {
+ Eval("cd /tmp")
+ d, _ := os.Getwd()
+
+ if d != "/tmp" {
+ t.Errorf("Expected %q, got %q\n", "/tmp", d)
+ }
+}
+
+func TestCdFail(t *testing.T) {
+ c, _ := os.Getwd()
+ err := Eval("cd /root")
+ t.Logf("%v\n", err)
+
+ d, _ := os.Getwd()
+ if c != d || err == nil {
+ t.Errorf("Expected %q, got %q\n", c, d)
+ }
+}
+
+func TestExport(t *testing.T) {
+ err := Eval("export TEST=true")
+ test := os.Getenv("TEST")
+
+ if err != nil {
+ t.Errorf("%v\n", err)
+ }
+ if test != "true" {
+ t.Errorf("Expected %q, got %q\n", "true", test)
+ }
+}
+
+func TestExportFail(t *testing.T) {
+ err := Eval("export TEST = 123")
+ if err == nil {
+ t.Errorf("Didn't get error\n")
+ }
+ t.Logf("%v\n", err)
+}
+
+func TestUnset(t *testing.T) {
+ err := Eval("unset TEST")
+ test := os.Getenv("TEST")
+
+ if err != nil {
+ t.Logf("%v\n", err)
+ }
+ if test != "" {
+ t.Errorf("Expected empty string, got %q\n", test)
+ }
+}