Eric Bower
·
2026-09-19
1#!/usr/bin/env bats
2# CLI argument validation tests for zmx.
3# See https://github.com/neurosnap/zmx/issues/178
4
5load test_helper
6
7# ============================================================================
8# Invalid commands must exit non-zero
9# ============================================================================
10
11@test "unknown command exits non-zero" {
12 run "$ZMX" foo
13 [ "$status" -ne 0 ]
14 [[ "$output" == *"unknown command"* ]]
15}
16
17@test "unknown command alias exits non-zero" {
18 run "$ZMX" not-a-real-command
19 [ "$status" -ne 0 ]
20 [[ "$output" == *"unknown command"* ]]
21}
22
23@test "completions with invalid shell exits non-zero" {
24 run "$ZMX" completions foo
25 [ "$status" -ne 0 ]
26 [[ "$output" == *"unknown shell"* ]]
27}
28
29@test "completions alias with invalid shell exits non-zero" {
30 run "$ZMX" c foo
31 [ "$status" -ne 0 ]
32 [[ "$output" == *"unknown shell"* ]]
33}
34
35@test "completions with no argument exits non-zero" {
36 run "$ZMX" completions
37 [ "$status" -ne 0 ]
38 [[ "$output" == *"shell argument"* ]]
39}
40
41@test "get with no argument outside session exits non-zero" {
42 run env -u ZMX_SESSION "$ZMX" get
43 [ "$status" -ne 0 ]
44 [[ "$output" == *"session name required"* ]]
45}
46
47@test "set with no argument outside session exits non-zero" {
48 run env -u ZMX_SESSION "$ZMX" set
49 [ "$status" -ne 0 ]
50 [[ "$output" == *"session name required"* ]]
51}
52
53@test "clear with no argument outside session exits non-zero" {
54 run env -u ZMX_SESSION "$ZMX" clear
55 [ "$status" -ne 0 ]
56 [[ "$output" == *"session name required"* ]]
57}
58
59@test "detach outside session exits non-zero" {
60 run env -u ZMX_SESSION "$ZMX" detach
61 [ "$status" -ne 0 ]
62 [[ "$output" == *"not inside a zmx session"* ]]
63}
64
65@test "history with no argument outside session exits non-zero" {
66 run env -u ZMX_SESSION "$ZMX" history
67 [ "$status" -ne 0 ]
68 [[ "$output" == *"session name required"* ]]
69}
70
71@test "kill with no argument exits non-zero" {
72 run "$ZMX" kill
73 [ "$status" -ne 0 ]
74 [[ "$output" == *"session name required"* ]]
75}
76
77@test "wait with no argument exits non-zero" {
78 run "$ZMX" wait
79 [ "$status" -ne 0 ]
80 [[ "$output" == *"session name required"* ]]
81}
82
83@test "tail with no argument exits non-zero" {
84 run "$ZMX" tail
85 [ "$status" -ne 0 ]
86 [[ "$output" == *"session name required"* ]]
87}
88
89@test "send with no argument exits non-zero" {
90 run "$ZMX" send
91 [ "$status" -ne 0 ]
92 [[ "$output" == *"session name required"* ]]
93}
94
95@test "print with no argument exits non-zero" {
96 run "$ZMX" print
97 [ "$status" -ne 0 ]
98 [[ "$output" == *"session name required"* ]]
99}
100
101@test "attach with missing labels value exits non-zero" {
102 run "$ZMX" attach --labels
103 [ "$status" -ne 0 ]
104 [[ "$output" == *"--labels requires"* ]]
105}
106
107@test "print-env with no argument outside session exits non-zero" {
108 run env -u ZMX_SESSION "$ZMX" print-env
109 [ "$status" -ne 0 ]
110 [[ "$output" == *"session name required"* ]]
111}
112
113@test "write with no argument exits non-zero" {
114 run "$ZMX" write
115 [ "$status" -ne 0 ]
116 [[ "$output" == *"session name required"* ]]
117}
118
119@test "write with missing file path exits non-zero" {
120 run "$ZMX" write dummy_session
121 [ "$status" -ne 0 ]
122 [[ "$output" == *"file path required"* ]]
123}
124
125# ============================================================================
126# Valid commands still exit zero
127# ============================================================================
128
129@test "help exits zero" {
130 run "$ZMX" help
131 [ "$status" -eq 0 ]
132}
133
134@test "version exits zero" {
135 run "$ZMX" version
136 [ "$status" -eq 0 ]
137}
138
139@test "completions with valid shell exits zero" {
140 run "$ZMX" completions bash
141 [ "$status" -eq 0 ]
142 [[ "$output" == *"_zmx_completions"* ]]
143
144 run "$ZMX" completions yash
145 [ "$status" -eq 0 ]
146 [[ "$output" == *"completion/zmx"* ]]
147}
148
149@test "completions --help exits zero" {
150 run "$ZMX" completions --help
151 [ "$status" -eq 0 ]
152}
153
154@test "print-env --help exits zero" {
155 run "$ZMX" print-env --help
156 [ "$status" -eq 0 ]
157}
158
159