Skip to content

Commit 3c98758

Browse files
Improve automation: use exit codes to determine success or fail.
1. Run in terminal 1: $PORT=3100 node app.js 2. Run in terminal 2: $( ./verifyscript.sh && if [ $? -lt 0 ]; then echo "failure, exit code -1"; elif [ $? -eq 0 ]; then echo "success, exit code 0"; elif [ $? -lt 0 ]; then echo "failure, exit code less than 1"; elif [ $? -gt 1 ]; then echo "exit code greater than 1"; fi ) 3. Result in terminal 2: expected output: radsauce success, child process exit code 0: OUTPUT is radsauce 4. Result in termimal 1: expected output: radsauce 5. Note: the $? -lt 0 logic, meaning if process' exit code is less than 0, was used on the command line, in addition to logic of string comparison within verifyscript.sh. Which is most effective?
1 parent 3a4211d commit 3c98758

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
* header to plain text, and verify the output by echoing the
2929
* -d data=variable in the server response (the POST handler below):
3030
*
31-
* $ curl -X POST -d name=radsauce http://localhost:3100/foo -v
32-
* -H "Content-Type: text/plain"
31+
* $ curl -X POST -d name=radsauce http://localhost:3100/foo
32+
* -H "Content-Type: text/plain"
3333
*
3434
* The above changes existing Content-Type HTTP header to send a MIME type /
3535
* data type message of plain text. (Default is urlencoded).

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "helloworld",
33
"version": "1.0.0",
44
"description": "a first Express.js project. August 7th 2016, AF.",
5-
"main": "index.js",
5+
"main": "app.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": ""
11+
"url": "github.com/abstractmachines/express1"
1212
},
1313
"author": "A. Falke",
1414
"license": "ISC",

verifyscript.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
#expected output after terminal 2 curl's:
55
#radsauce
66

7-
#terminal 2: ./verifyscript.sh && echo "it worked" || echo "fail"
8-
#expected output:
7+
#terminal 2: ./verifyscript.sh && echo "it worked" || echo "fail" etc
8+
#
9+
# Specific command to run in terminal 2 is:
10+
#
11+
# ( ./verifyscript.sh && if [ $? -lt 0 ];
12+
# then echo "failure, exit code -1";
13+
# elif [ $? -eq 0 ]; then echo "success, exit code 0";
14+
# elif [ $? -lt 0 ]; then echo "failure, exit code less than 1";
15+
# elif [ $? -gt 1 ]; then echo "exit code greater than 1"; fi )
916
# radsauce
1017
# success, child process exit code 0: OUTPUT is radsauce
11-
# it worked
1218

1319
OUTPUT="$(curl --request POST -d radsauce http://localhost:3100/foo -H "Content-Type: text/plain" 2>/dev/null )"
1420

1521
echo "${OUTPUT}"
1622

23+
# possible alternative:
24+
# if [ $? -eq 0 ]; then
1725

1826
if [ "${OUTPUT}" = "radsauce" ]; then
1927

0 commit comments

Comments
 (0)