Ticket #3752: 3752-0001-extfs-tester-use-lowercase-for-private-variables.patch

File 3752-0001-extfs-tester-use-lowercase-for-private-variables.patch, 6.0 KB (added by mooffie, 8 years ago)
  • tests/src/vfs/extfs/helpers-list/test_all

    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 
    5656############################ Global variables ############################## 
    5757 
    5858# The directories used. 
    59 DATA_DIR= 
    60 HELPERS_DIR1= 
    61 HELPERS_DIR2= 
     59data_dir= 
     60helpers_dir1= 
     61helpers_dir2= 
    6262 
    6363opt_create_output=no        # "yes" if '--create-output' provided. 
    6464opt_run_mcdiff_on_error=no  # "yes" if '--mcdiff' provided. 
    has_colors() { 
    113113 
    114114init_colors() { 
    115115  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" 
    122122  fi 
    123123} 
    124124 
    run() { 
    185185  local error_count=0 
    186186  local pass_count=0 
    187187 
    188   for INPUT in "$DATA_DIR"/*.input; do 
     188  for input in "$data_dir"/*.input; do 
    189189 
    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. 
    191191 
    192     header "Testing $INPUT" 
     192    header "Testing $input" 
    193193 
    194     has_string "$INPUT" " " && die "Error: filename contains spaces." 
     194    has_string "$input" " " && die "Error: filename contains spaces." 
    195195 
    196196    # 
    197197    # Set up variables: 
    198198    # 
    199199 
    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" 
    204204 
    205205    local do_create_output=no 
    206206 
    run() { 
    220220      fi 
    221221    fi 
    222222 
    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" 
    226226 
    227227    local extra_parser_args="" 
    228228    [ -f "$args_file" ] && extra_parser_args="$(cat "$args_file")" 
    run() { 
    235235    # 
    236236 
    237237    ( 
    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. 
    239239    export MC_TEST_EXTFS_LIST_CMD 
    240240    if [ -f "$env_vars_file" ]; then 
    241241      set -a  # "allexport: Export all variables assigned to." 
    run() { 
    255255       err 
    256256       err "You may try running the helper yourself with:" 
    257257       err 
    258        err "  \$ MC_TEST_EXTFS_LIST_CMD=\"mc_xcat $INPUT\" \\" 
     258       err "  \$ MC_TEST_EXTFS_LIST_CMD=\"mc_xcat $input\" \\" 
    259259       err "      $helper_CMD list /dev/null" 
    260260       err 
    261261       continue 
    run() { 
    296296       err 
    297297       if [ $opt_run_mcdiff_on_error = "yes" ]; then 
    298298         notice "Hit ENTER to launch mcdiff ..." 
    299          read DUMMY_VAR  # dash needs this. 
     299         read dummy_var  # dash needs this. 
    300300         ${MCDIFF:-mcdiff} "$expected_parsed_output" "$actual_parsed_output" 
    301301       else 
    302302         notice "Tip: invoke this program with '--mcdiff' to automatically launch" 
    parse_command_line_arguments() { 
    325325  while [ -n "$1" ]; do 
    326326    case "$1" in 
    327327      --data-dir) 
    328         DATA_DIR=$2 
     328        data_dir=$2 
    329329        shift 2 
    330330        ;; 
    331331      --helpers-dir) 
    332         if [ -z "$HELPERS_DIR1" ]; then 
    333           HELPERS_DIR1=$2 
     332        if [ -z "$helpers_dir1" ]; then 
     333          helpers_dir1=$2 
    334334        else 
    335           HELPERS_DIR2=$2 
     335          helpers_dir2=$2 
    336336        fi 
    337337        shift 2 
    338338        ;; 
    parse_command_line_arguments() { 
    359359# Check that everything is set up correctly. 
    360360# 
    361361verify_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. 
    365365 
    366366  local dir 
    367   for dir in "$DATA_DIR" "$HELPERS_DIR1" "$HELPERS_DIR2"; do 
     367  for dir in "$data_dir" "$helpers_dir1" "$helpers_dir2"; do 
    368368    assert_dir_exists "$dir" 
    369369    has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames."  # search "reason", twice, above. 
    370370  done