From 597f8c96cce57cf82907ff5c27eaf3d4ab137886 Mon Sep 17 00:00:00 2001 From: leogtzr Date: Fri, 7 Sep 2018 10:19:00 -0600 Subject: [PATCH 1/3] cleanup --- nextnumber | 15 ++++++++++----- quickrun | 4 +++- quicktest | 4 ++-- striptests | 28 +++++++++++----------------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/nextnumber b/nextnumber index 6b91a92..f70ec50 100755 --- a/nextnumber +++ b/nextnumber @@ -1,13 +1,18 @@ #!/usr/bin/env bash # TODO: Find a less trashy way to get the next available error code -if ! shopt -s globstar -then +if ! shopt -s globstar; then echo "Error: This script depends on Bash 4." >&2 exit 1 fi -for i in 1 2 -do - last=$(grep -hv "^prop" ./**/*.hs | grep -Ewo "$i[0-9]{3}" | sort -n | tail -n 1) +for i in 1 2; do + last=$(grep --no-filename --invert-match "^prop" ./**/*.hs \ + | grep --extended-regexp --word-regexp --only-matching "$i[0-9]{3}" \ + | sort --numeric-sort \ + | tail --lines 1 +) echo "Next ${i}xxx: $((last+1))" done + +exit 0 + diff --git a/quickrun b/quickrun index 4bdf8eb..67d1d92 100755 --- a/quickrun +++ b/quickrun @@ -1,5 +1,7 @@ -#!/bin/bash +#!/usr/bin/env bash # quickrun runs ShellCheck in an interpreted mode. # This allows testing changes without recompiling. runghc -isrc -idist/build/autogen shellcheck.hs "$@" + +exit \ No newline at end of file diff --git a/quicktest b/quicktest index f4ed0b3..0654189 100755 --- a/quicktest +++ b/quicktest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # quicktest runs the ShellCheck unit tests in an interpreted mode. # This allows running tests without compiling, which can be faster. # 'cabal test' remains the source of truth. @@ -16,7 +16,7 @@ if [[ $var == *$'\nTrue'* ]] then exit 0 else - grep -C 3 -e "Fail" -e "Tracing" <<< "$var" + grep --context 3 --regexp "Fail" --regexp "Tracing" <<< "${var}" exit 1 fi ) 2>&1 diff --git a/striptests b/striptests index 78c5220..679068f 100755 --- a/striptests +++ b/striptests @@ -5,15 +5,14 @@ set -o pipefail sponge() { - data="$(cat)" - printf '%s\n' "$data" > "$1" + local -r DATA="$(cat)" + printf '%s\n' "${DATA}" > "${1}" } modify() { - if ! "${@:2}" < "$1" | sponge "$1" - then + if ! "${@:2}" < "${1}" | sponge "${1}" { - printf 'Failed to modify %s: ' "$1" + printf 'Failed to modify %s: ' "${1}" printf '%q ' "${@:2}" printf '\n' } >&2 @@ -50,28 +49,23 @@ detestify() { ' } - - -if [[ ! -e ShellCheck.cabal ]] -then +if [[ ! -e 'ShellCheck.cabal' ]]; then echo "Run me from the ShellCheck directory." >&2 exit 1 fi -if [[ -d '.git' ]] && ! git diff --exit-code > /dev/null 2>&1 -then +if [[ -d '.git' ]] && ! git diff --exit-code > /dev/null 2>&1; then echo "You have local changes! These may be overwritten." >&2 exit 2 fi -modify ShellCheck.cabal sed -e ' +modify 'ShellCheck.cabal' sed -e ' /QuickCheck/d /^test-suite/{ s/.*//; q; } ' -find . -name '.git' -prune -o -type f -name '*.hs' -print | - while IFS= read -r file - do - modify "$file" detestify - done +while IFS= read -r file; do + modify "${file}" detestify +done < <(find . -name '.git' -prune -o -type f -name '*.hs' -print) +exit 0 From a23f46249d138062507fc24a96a3ff69594d5c2c Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 9 Sep 2018 21:11:43 -0600 Subject: [PATCH 2/3] changing long options with short options and K&R style --- nextnumber | 12 +++++------- quicktest | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/nextnumber b/nextnumber index f70ec50..8e87f8f 100755 --- a/nextnumber +++ b/nextnumber @@ -1,16 +1,14 @@ #!/usr/bin/env bash # TODO: Find a less trashy way to get the next available error code -if ! shopt -s globstar; then +if ! shopt -s globstar +then echo "Error: This script depends on Bash 4." >&2 exit 1 fi -for i in 1 2; do - last=$(grep --no-filename --invert-match "^prop" ./**/*.hs \ - | grep --extended-regexp --word-regexp --only-matching "$i[0-9]{3}" \ - | sort --numeric-sort \ - | tail --lines 1 -) +for i in 1 2 +do + last=$(grep -hv "^prop" ./**/*.hs | grep -Ewo "$i[0-9]{3}" | sort -n | tail -n 1) echo "Next ${i}xxx: $((last+1))" done diff --git a/quicktest b/quicktest index 0654189..4eab80b 100755 --- a/quicktest +++ b/quicktest @@ -16,7 +16,7 @@ if [[ $var == *$'\nTrue'* ]] then exit 0 else - grep --context 3 --regexp "Fail" --regexp "Tracing" <<< "${var}" + grep -C 3 -e "Fail" -e "Tracing" <<< "${var}" exit 1 fi ) 2>&1 From c9c8de525dc3a7c173bdc0d254bd8245373dbe6d Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 15 Sep 2018 15:02:48 -0600 Subject: [PATCH 3/3] rolling back k&r --- striptests | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/striptests b/striptests index 679068f..8fe3182 100755 --- a/striptests +++ b/striptests @@ -49,7 +49,8 @@ detestify() { ' } -if [[ ! -e 'ShellCheck.cabal' ]]; then +if [[ ! -e 'ShellCheck.cabal' ]] +then echo "Run me from the ShellCheck directory." >&2 exit 1 fi