From aa035048ed8791f9add7f56fbc4611bc4b2be2ab Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Sat, 7 Jan 2017 19:11:30 +0200
Subject: [PATCH 1/3] Ticket #3752: extfs: tester: use lowercase for private
variables.
We switch to a modern practice of using lowercase for private variables ("shell
variables") and uppercase for the system's ("environment variables"). Constants
too are made lowercase, as it takes a philosopher to define "constant".
This gives us two advantages:
- If an .env_vars file accesses a private variable (e.g. $DATA_DIR or $INPUT),
something we want to discourage, we'll easily see this.
- Somewhat confusing code like "MC_TEST_DATA_DIR=$DATA_DIR" (which was to occur
in the following patch) becomes self-documenting after the change.
Signed-off-by: Mooffie <mooffie@gmail.com>
---
tests/src/vfs/extfs/helpers-list/test_all | 62 +++++++++++++++----------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/tests/src/vfs/extfs/helpers-list/test_all b/tests/src/vfs/extfs/helpers-list/test_all
index 89d5c77..0652c9d 100755
a
|
b
|
EOS |
56 | 56 | ############################ Global variables ############################## |
57 | 57 | |
58 | 58 | # The directories used. |
59 | | DATA_DIR= |
60 | | HELPERS_DIR1= |
61 | | HELPERS_DIR2= |
| 59 | data_dir= |
| 60 | helpers_dir1= |
| 61 | helpers_dir2= |
62 | 62 | |
63 | 63 | opt_create_output=no # "yes" if '--create-output' provided. |
64 | 64 | opt_run_mcdiff_on_error=no # "yes" if '--mcdiff' provided. |
… |
… |
has_colors() { |
113 | 113 | |
114 | 114 | init_colors() { |
115 | 115 | if has_colors; then |
116 | | ESC=$(printf '\033') # for portability |
117 | | C_bold="$ESC[1m" |
118 | | C_green="$ESC[1;32m" |
119 | | C_red="$ESC[1;31m" |
120 | | C_magenta="$ESC[1;35m" |
121 | | C_norm="$ESC[0m" |
| 116 | local esc="$(printf '\033')" # for portability |
| 117 | C_bold="$esc[1m" |
| 118 | C_green="$esc[1;32m" |
| 119 | C_red="$esc[1;31m" |
| 120 | C_magenta="$esc[1;35m" |
| 121 | C_norm="$esc[0m" |
122 | 122 | fi |
123 | 123 | } |
124 | 124 | |
… |
… |
run() { |
185 | 185 | local error_count=0 |
186 | 186 | local pass_count=0 |
187 | 187 | |
188 | | for INPUT in "$DATA_DIR"/*.input; do |
| 188 | for input in "$data_dir"/*.input; do |
189 | 189 | |
190 | | has_string "$INPUT" '\*' && break # we can't use 'shopt -s nullglob' as it's bash-specific. |
| 190 | has_string "$input" '\*' && break # we can't use 'shopt -s nullglob' as it's bash-specific. |
191 | 191 | |
192 | | header "Testing $INPUT" |
| 192 | header "Testing $input" |
193 | 193 | |
194 | | has_string "$INPUT" " " && die "Error: filename contains spaces." |
| 194 | has_string "$input" " " && die "Error: filename contains spaces." |
195 | 195 | |
196 | 196 | # |
197 | 197 | # Set up variables: |
198 | 198 | # |
199 | 199 | |
200 | | local helper_name="$(basename_sans_extensions "$INPUT")" |
201 | | local expected_parsed_output="${INPUT%.input}.output" |
202 | | local env_vars_file="${INPUT%.input}.env_vars" |
203 | | local args_file="${INPUT%.input}.args" |
| 200 | local helper_name="$(basename_sans_extensions "$input")" |
| 201 | local expected_parsed_output="${input%.input}.output" |
| 202 | local env_vars_file="${input%.input}.env_vars" |
| 203 | local args_file="${input%.input}.args" |
204 | 204 | |
205 | 205 | local do_create_output=no |
206 | 206 | |
… |
… |
run() { |
220 | 220 | fi |
221 | 221 | fi |
222 | 222 | |
223 | | find_helper "$helper_name" "$HELPERS_DIR1" || |
224 | | find_helper "$helper_name" "$HELPERS_DIR2" || |
225 | | die "I can't find helper '$helper_name' in either $HELPERS_DIR1 or $HELPERS_DIR2" |
| 223 | find_helper "$helper_name" "$helpers_dir1" || |
| 224 | find_helper "$helper_name" "$helpers_dir2" || |
| 225 | die "I can't find helper '$helper_name' in either $helpers_dir1 or $helpers_dir2" |
226 | 226 | |
227 | 227 | local extra_parser_args="" |
228 | 228 | [ -f "$args_file" ] && extra_parser_args="$(cat "$args_file")" |
… |
… |
run() { |
235 | 235 | # |
236 | 236 | |
237 | 237 | ( |
238 | | MC_TEST_EXTFS_LIST_CMD="mc_xcat $INPUT" # reason #2 we don't allow spaces in pathnames. |
| 238 | MC_TEST_EXTFS_LIST_CMD="mc_xcat $input" # reason #2 we don't allow spaces in pathnames. |
239 | 239 | export MC_TEST_EXTFS_LIST_CMD |
240 | 240 | if [ -f "$env_vars_file" ]; then |
241 | 241 | set -a # "allexport: Export all variables assigned to." |
… |
… |
run() { |
255 | 255 | err |
256 | 256 | err "You may try running the helper yourself with:" |
257 | 257 | err |
258 | | err " \$ MC_TEST_EXTFS_LIST_CMD=\"mc_xcat $INPUT\" \\" |
| 258 | err " \$ MC_TEST_EXTFS_LIST_CMD=\"mc_xcat $input\" \\" |
259 | 259 | err " $helper_CMD list /dev/null" |
260 | 260 | err |
261 | 261 | continue |
… |
… |
run() { |
296 | 296 | err |
297 | 297 | if [ $opt_run_mcdiff_on_error = "yes" ]; then |
298 | 298 | notice "Hit ENTER to launch mcdiff ..." |
299 | | read DUMMY_VAR # dash needs this. |
| 299 | read dummy_var # dash needs this. |
300 | 300 | ${MCDIFF:-mcdiff} "$expected_parsed_output" "$actual_parsed_output" |
301 | 301 | else |
302 | 302 | notice "Tip: invoke this program with '--mcdiff' to automatically launch" |
… |
… |
parse_command_line_arguments() { |
325 | 325 | while [ -n "$1" ]; do |
326 | 326 | case "$1" in |
327 | 327 | --data-dir) |
328 | | DATA_DIR=$2 |
| 328 | data_dir=$2 |
329 | 329 | shift 2 |
330 | 330 | ;; |
331 | 331 | --helpers-dir) |
332 | | if [ -z "$HELPERS_DIR1" ]; then |
333 | | HELPERS_DIR1=$2 |
| 332 | if [ -z "$helpers_dir1" ]; then |
| 333 | helpers_dir1=$2 |
334 | 334 | else |
335 | | HELPERS_DIR2=$2 |
| 335 | helpers_dir2=$2 |
336 | 336 | fi |
337 | 337 | shift 2 |
338 | 338 | ;; |
… |
… |
parse_command_line_arguments() { |
359 | 359 | # Check that everything is set up correctly. |
360 | 360 | # |
361 | 361 | verify_setup() { |
362 | | [ -n "$DATA_DIR" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info." |
363 | | [ -n "$HELPERS_DIR1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info." |
364 | | [ -z "$HELPERS_DIR2" ] && HELPERS_DIR2=$HELPERS_DIR1 # we're being lazy. |
| 362 | [ -n "$data_dir" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info." |
| 363 | [ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info." |
| 364 | [ -z "$helpers_dir2" ] && helpers_dir2=$helpers_dir1 # we're being lazy. |
365 | 365 | |
366 | 366 | local dir |
367 | | for dir in "$DATA_DIR" "$HELPERS_DIR1" "$HELPERS_DIR2"; do |
| 367 | for dir in "$data_dir" "$helpers_dir1" "$helpers_dir2"; do |
368 | 368 | assert_dir_exists "$dir" |
369 | 369 | has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames." # search "reason", twice, above. |
370 | 370 | done |