forked from HariSekhon/DevOps-Python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_center.sh
More file actions
executable file
·134 lines (105 loc) · 3.73 KB
/
test_center.sh
File metadata and controls
executable file
·134 lines (105 loc) · 3.73 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2016-01-29 21:45:49 +0000 (Fri, 29 Jan 2016)
#
# https://github.com/harisekhon
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback
#
# https://www.linkedin.com/in/harisekhon
#
# Quick tests, need to replace with testcmd.exp
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$srcdir/.."
. "bash-tools/lib/utils.sh"
section "Testing center.py"
expected=" <this is a test>"
echo "testing args:"
#run_output "$expected" ./center.py " <this is a test> "
echo "testing stdin:"
run_output "$expected" ./center.py <<< "<this is a test>"
expected=" <this is a test>"
echo "testing multi-args:"
run_output "$expected" ./center.py "<this" is a "test> "
###########
# comment
expected="# this is a test"
echo "testing args with # prefix:"
run_output "$expected" ./center.py " # this is a test "
echo "testing stdin with # prefix:"
run_output "$expected" ./center.py <<< " # this is a test"
expected="// this is a test"
echo "testing args with // prefix:"
run_output "$expected" ./center.py " // this is a test "
echo "testing stdin with // prefix:"
run_output "$expected" ./center.py <<< " // this is a test"
###########
# comment handling disabled
expected=" # this is a test"
echo "testing args with # prefix with comment handling disabled:"
# doesn't preserve whitespace correctly
#run_output "$expected" ./center.py -n " # this is a test "
result="$(./center.py -n " # this is a test ")"
run++
if [ "$result" = "$expected" ]; then
echo "Succeeded in centering args with # prefix with comment handling disabled"
else
echo "Failed to center args with # prefix with comment handling disabled"
echo "Expected: '$expected'"
echo "Got: '$result'"
exit 1
fi
echo
hr
echo "testing stdin with # prefix with comment handling disabled:"
run_output "$expected" ./center.py -n <<< " # this is a test"
expected=" // this is a test"
echo "testing args with // prefix with comment handling disabled:"
# doesn't preserve whitespace correctly
#run_output "$expected" ./center.py -n " // this is a test "
result="$(./center.py -n " // this is a test ")"
run++
if [ "$result" = "$expected" ]; then
echo "Succeeded in centering args with // prefix with comment handling disabled"
else
echo "Failed to center args with // prefix with comment handling disabled"
echo "Expected: '$expected'"
echo "Got: '$result'"
exit 1
fi
echo
hr
echo "testing stdin with // prefix:"
run_output "$expected" ./center.py -n <<< " // this is a test"
#######################
# space in middle tests
expected=" < t h i s i s a t e s t >"
echo "testing spacing with arg:"
# doesn't preserve whitespace correctly
#run_output "$expected" ./center.py -s " <this is a test> "
result="$(./center.py -s " <this is a test> ")"
run++
if [ "$result" = "$expected" ]; then
echo "Succeeded in centering args with // prefix with comment handling disabled"
else
echo "Failed to center args with // prefix with comment handling disabled"
echo "Expected: '$expected'"
echo "Got: '$result'"
exit 1
fi
echo
hr
echo "testing spacing with stdin:"
run_output "$expected" ./center.py -s <<< " <this is a test> "
echo
echo "Completed $run_count tests"
echo
echo "All tests for center.py completed successfully"
echo
echo