1 | #!/usr/bin/env bash
|
2 |
|
3 | #
|
4 | # cli-test: Tests for forever CLI
|
5 | #
|
6 | # (C) 2012 Charlie Robbins & the Contributors
|
7 | # MIT LICENSE
|
8 | #
|
9 |
|
10 | # Yes, we have tests in bash. How mad science is that?
|
11 |
|
12 | alias forever=bin/forever
|
13 | script="test/fixtures/log-on-interval.js"
|
14 |
|
15 | function fail {
|
16 | echo "\033[31m ✘ $1\033[0m"
|
17 | exit 1
|
18 | }
|
19 |
|
20 | function success {
|
21 | echo "\033[32m ✔ $1\033[0m"
|
22 | }
|
23 |
|
24 | function spec {
|
25 | [ $? -eq 0 ] || fail "$1"
|
26 | success "$1"
|
27 | }
|
28 |
|
29 | echo "\033[1mRunning tests:\033[0m"
|
30 |
|
31 | # First kill all processes and remove forever directory to ensure clean
|
32 | # environment
|
33 | forever stopall
|
34 | rm -rf ~/.forever
|
35 |
|
36 | # Spawn some process
|
37 | forever start "$script"
|
38 |
|
39 | # Assert that forever actually spawned a process and that it's in `forever list`
|
40 | sleep 1 # it takes some time until process appears in `forever list`
|
41 | forever list | grep "$script"
|
42 | spec "\`forever list\` should contain spawned process"
|
43 |
|
44 | # `forever stop` should output process it stopped...
|
45 | forever stop 0 | grep "$script"
|
46 | spec "\`forever stop 0\` should contain stopped process"
|
47 |
|
48 | # ... and actually stop it
|
49 | forever list | grep -v "$script"
|
50 | spec "\`forever stop 0\` should actually stop the process"
|
51 |
|