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