66
77# Commander
88
9- ` Commander ` is an alternative to ` bats ` and ` gotest.tools/icmd ` for testing cli apps.
9+
10+ Define language independent tests for your command line scripts and programs in simple ` yaml ` files.
1011
1112 - It runs on ` windows ` , ` osx ` and ` linux `
1213 - It is a self-contained binary - no need to install a heavy lib or language
@@ -33,35 +34,120 @@ chmod +x commander
3334 - Add the path to your [ path] ( https://docs.alfresco.com/4.2/tasks/fot-addpath.html ) environment variable
3435 - Test it: ` commander --version `
3536
36- ## Example
3737
38- You can find more examples in ` examples/ `
38+ ## Quick start
3939
40- ```
41- # Build the project
42- $ make build
40+ ` Commander ` will always search for a default ` commander.yaml ` in the current working directory and execute all defined tests in it.
41+
42+
43+ ``` bash
44+ # You can even let commander add tests for you!
45+ $ ./commander test examples/commander.yaml
46+ tests:
47+ echo hello:
48+ exit-code: 0
49+ stdout: hello
4350
44- # Execute test suite
45- Starting test file examples/commander.yaml...
51+ written to /tmp/commander.yaml
52+
53+ # ... and execute!
54+ $ ./commander test
55+ Starting test file commander.yaml...
4656
47- ✓ it should print hello world
4857✓ echo hello
49- ✓ it should validate exit code
50- ✓ it should fail
5158
52- Duration: 0.005s
53- Count: 4 , Failed: 0
59+ Duration: 0.002s
60+ Count: 1 , Failed: 0
5461```
5562
56- ## Minimal test
63+ ## Complete YAML file
64+
65+ Here you can see an example with all features.
5766
5867``` yaml
68+ config : # Config for all executed tests
69+ dir : /tmp # Set working directory
70+ env : # Environment variables
71+ KEY : global
72+ timeout : 5000 # Timeout in ms
73+ retries : 2 # Define retries for each test
74+
5975tests :
60- echo hello :
61- stdout : hello
76+ echo hello : # Define command as title
77+ stdout : hello # Default is to check if it contains the given characters
78+ exit-code : 0 # Assert exit-code
79+
80+ it should fail :
81+ command : invalid
82+ stderr :
83+ contains :
84+ - invalid # Assert only contain work
85+ exactly : " /bin/sh: 1: invalid: not found"
86+ line-count : 1 # Assert amount of lines
87+ lines : # Assert specific lines
88+ 1 : " /bin/sh: 1: invalid: not found"
89+ exit-code : 127
90+
91+ it has configs :
92+ command : echo hello
93+ stdout :
94+ contains :
95+ - hello # See test "it should fail"
96+ exactly : hello
97+ line-count : 1
98+ config :
99+ dir : /home/user # Overwrite working dir
100+ env :
101+ KEY : local # Overwrite env variable
102+ ANOTHER : yeah # Add another env variable
103+ timeout : 1000 # Overwrite timeout
104+ retries : 5
62105 exit-code : 0
63106` ` `
64107
108+ ## Executing
109+
110+ ` ` ` bash
111+ # Execute file commander.yaml in current directory
112+ $ ./commander test
113+
114+ # Execute a specific suite
115+ $ ./commander test /tmp/test.yaml
116+
117+ # Execute a single test
118+ $ ./commander test /tmp/test.yaml "my test"
119+ ```
120+
121+ ## Adding tests
122+
123+ You can use the ` add ` argument if you want to ` commander ` to create your tests.
124+
125+ ``` bash
126+ # Add a test to the default commander.yaml
127+ $ ./commander add echo hello
128+ written to /tmp/commander.yaml
129+
130+ # Write to a given file
131+ $ ./commander add --file=test.yaml echo hello
132+ written to test.yaml
133+
134+ # Write to stdout and file
135+ $ ./commander add --stdout echo hello
136+ tests:
137+ echo hello:
138+ exit-code: 0
139+ stdout: hello
140+
141+ written to /tmp/commander.yaml
142+
143+ # Only to stdout
144+ $ ./commander add --stdout --no-file echo hello
145+ tests:
146+ echo hello:
147+ exit-code: 0
148+ stdout: hello
149+ ```
150+
65151## Usage
66152
67153```
@@ -85,7 +171,7 @@ GLOBAL OPTIONS:
85171## Development
86172
87173```
88- # Initialise dev env
174+ # Initialise dev environment
89175$ make init
90176
91177# Build the project binary
0 commit comments