Skip to content

Commit 8860e6c

Browse files
authored
Updated **run_all_unit_tests.sh** (latest from https://github.com/synesissoftware/misc-dev-scripts) (#2)
1 parent 0f24a9c commit 8860e6c

2 files changed

Lines changed: 101 additions & 54 deletions

File tree

‎Gemfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ source "https://rubygems.org"
44

55
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
66

7-
gem 'xqsr3', [ '~> 0.39', '>= 0.39.2' ]
7+
gem 'xqsr3', [ '~> 0.39', '>= 0.39.3' ]
88

‎run_all_unit_tests.sh‎

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# File: run_all_unit_tests.sh
55
#
66
# Purpose: Executes the unit-tests of a Ruby project regardless of
7-
# calling directory
7+
# calling directory, allowing use of debug mode, warnings, and
8+
# executing each rbenv version
89
#
910
# Created: 9th June 2011
10-
# Updated: 2nd April 2024
11+
# Updated: 16th March 2025
1112
#
12-
# Copyright (c) Matthew Wilson, 2011-2024
13+
# Copyright (c) Matthew Wilson, 2011-2025
1314
# All rights reserved
1415
#
1516
# Redistribution and use in source and binary forms, with or without
@@ -47,11 +48,11 @@
4748
Source="${BASH_SOURCE[0]}"
4849
while [ -h "$Source" ]; do
4950

50-
Dir="$(cd -P "$(dirname "$Source")" && pwd)"
51+
ScriptDir="$(cd -P "$(dirname "$Source")" && pwd)"
5152
Source="$(readlink "$Source")"
52-
[[ $Source != /* ]] && Source="$Dir/$Source"
53+
[[ $Source != /* ]] && Source="$ScriptDir/$Source"
5354
done
54-
Dir="$(cd -P "$( dirname "$Source" )" && pwd)"
55+
ScriptDir="$(cd -P "$( dirname "$Source" )" && pwd)"
5556

5657

5758
# colours
@@ -71,17 +72,44 @@ else
7172
fi
7273

7374

75+
# special command-line handling ('--pwd')
76+
77+
ProjectDir="$ScriptDir"
78+
79+
for arg in "$@"
80+
do
81+
82+
case "$arg" in
83+
84+
--pwd)
85+
86+
ProjectDir=$(pwd)
87+
;;
88+
*)
89+
90+
Arguments="$Arguments $arg"
91+
;;
92+
esac
93+
done
94+
95+
7496
# special command-line handling ('--rbenv-versions')
7597
# rbenv handling
7698

77-
RunRbEnvAllVersions=
7899
Arguments=
100+
FoundHelp=
101+
RunRbEnvAllVersions=
79102

80103
for arg in "$@"
81104
do
82105

83106
case "$arg" in
84107

108+
--help)
109+
110+
FoundHelp=1
111+
Arguments="$Arguments $arg"
112+
;;
85113
--rbenv-versions)
86114

87115
RunRbEnvAllVersions=1
@@ -93,6 +121,11 @@ do
93121
esac
94122
done
95123

124+
if [ ! -z "$FoundHelp" ]; then
125+
126+
RunRbEnvAllVersions=
127+
fi
128+
96129
if [ ! -z "$RunRbEnvAllVersions" ]; then
97130

98131
if ! command -v rbenv > /dev/null; then
@@ -102,17 +135,17 @@ if [ ! -z "$RunRbEnvAllVersions" ]; then
102135
exit 1
103136
fi
104137

105-
if [ ! -e "$Dir/.ruby-version" ];then
138+
if [ ! -e "$ProjectDir/.ruby-version" ];then
106139

107140
>&2 echo "$0: ${RbEnvClr_Red}${RbEnvClr_Bold}.ruby-version${RbEnvClr_None} file not detected"
108141

109142
exit 1
110143
fi
111144

112145
exclusions=()
113-
if [ -e "$Dir/.ruby-version-exclusions" ]; then
146+
if [ -e "$ProjectDir/.ruby-version-exclusions" ]; then
114147

115-
exclusion_lines=`cat "$Dir/.ruby-version-exclusions"`
148+
exclusion_lines=`cat "$ProjectDir/.ruby-version-exclusions"`
116149
for line in $exclusion_lines; do
117150

118151
exclusions+=($line)
@@ -177,62 +210,76 @@ fi
177210

178211
Separate=
179212
DebugFlag=
213+
WarningsFlag=-W0
180214

181215
for v in "$@"
182216
do
183217

184-
case "$v" in
185-
186-
--debug)
187-
188-
DebugFlag=--debug
189-
;;
190-
191-
--help)
192-
193-
echo "USAGE: $Source { | --help | [ --debug ] [ --separate ] }"
194-
echo
195-
echo "flags:"
196-
echo
197-
echo " --help"
198-
echo " shows this help and terminates"
199-
echo
200-
echo " --debug"
201-
echo " executes Ruby interpreter in debug mode"
202-
echo
203-
echo " --rbenv-versions"
204-
echo " executes this script (with all other specified arguments) for each rbenv version (except those listed in the file .ruby-version-exclusions, if present)"
205-
echo
206-
echo " --separate"
207-
echo " executes each unit-test in a separate program"
208-
echo
209-
210-
exit
211-
;;
212-
213-
--separate)
214-
215-
Separate=true
216-
;;
217-
218-
*)
219-
220-
echo "unrecognised argument; use --help for usage"
221-
222-
exit 1
223-
;;
224-
esac
218+
case "$v" in
219+
220+
--debug)
221+
222+
DebugFlag=--debug
223+
;;
224+
--help)
225+
226+
echo "USAGE: $Source { | --help | [ --debug ] [ --pwd ] [ --rbenv-versions ] [ --separate ] [ --warnings ]}"
227+
echo
228+
echo "flags:"
229+
echo
230+
echo " --help"
231+
echo " shows this help and terminates"
232+
echo
233+
echo " --debug"
234+
echo " executes Ruby interpreter in debug mode"
235+
echo
236+
echo " --pwd"
237+
echo " executes from present working directory, rather than relative to the script directory"
238+
echo
239+
echo " --rbenv-versions"
240+
echo " executes this script (with all other specified arguments) for each rbenv version (except those listed in the file .ruby-version-exclusions, if present)"
241+
echo
242+
echo " --separate"
243+
echo " executes each unit-test in a separate program"
244+
echo
245+
echo " --warnings"
246+
echo " executes Ruby interpreter in warnings mode"
247+
echo
248+
249+
exit
250+
;;
251+
--pwd)
252+
253+
# already-processed as special case above
254+
;;
255+
--separate)
256+
257+
Separate=true
258+
;;
259+
--warnings|--warn)
260+
261+
WarningsFlag=-W2 #-W:performance
262+
;;
263+
*)
264+
265+
>&2 echo "unrecognised argument '$v'; use --help for usage"
266+
267+
exit 1
268+
;;
269+
esac
225270
done
226271

272+
227273
# executing tests
228274

229275
if [ -z "$Separate" ]; then
230276

231-
ruby $DebugFlag "$Dir/test/unit/ts_all.rb"
277+
ruby $DebugFlag $WarningsFlag "$ProjectDir/test/unit/ts_all.rb"
232278
else
233279

234-
find "$Dir" -name 'tc_*.rb' -exec ruby $DebugFlag {} \;
280+
find "$ProjectDir" -name 'tc_*.rb' -exec ruby $DebugFlag $WarningsFlag {} \;
235281
fi
236282

283+
237284
# ############################## end of file ############################# #
238285

0 commit comments

Comments
 (0)