From 61cedf54f08172603e688aa52b70a96154822cc4 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 10 Jun 2014 22:00:18 -0400 Subject: [PATCH] .sh extension for included files Motivated by Google's shell coding standards. This makes sense for non-executable files. --- src/common | 262 ------------------------------- src/{expect-core => expect.sh} | 2 +- src/expect/{output => output.sh} | 2 +- src/run-spec | 2 +- src/{spec => spec.sh} | 4 +- src/{specstack => specstack.sh} | 0 src/{util => util.sh} | 0 7 files changed, 5 insertions(+), 267 deletions(-) delete mode 100644 src/common rename src/{expect-core => expect.sh} (98%) rename src/expect/{output => output.sh} (99%) rename src/{spec => spec.sh} (99%) rename src/{specstack => specstack.sh} (100%) rename src/{util => util.sh} (100%) diff --git a/src/common b/src/common deleted file mode 100644 index f721136..0000000 --- a/src/common +++ /dev/null @@ -1,262 +0,0 @@ -#!/bin/bash -# Common test case file -# -# Copyright (C) 2014 LoVullo Associates, Inc. -# -# This file is part of trello-sh. -# -# trello-sh is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -## - -declare -a __desc_stack=() -declare -i __desc_stackp=0 - -# current test csae -__desc_case= - -# stderr file -__desc_errpath="$(mktemp)" - -# most recent expect result and its exit code -__desc_result= -__desc_rexit=0 - -# most recent caller for assertions -__desc_caller= - - -__desc-push() -{ - __desc_stack[$__desc_stackp]="$*" - ((__desc_stackp++)) -} - -__desc-pop() -{ - [ "$__desc_stackp" -gt 0 ] || return 1 - - # notice that we unset before we decrease the pointer; this allows for a - # single level of un-popping - unset __desc_stack[$__desc_stackp] - ((__desc_stackp--)) -} - -__desc-unpop() -{ - ((__desc_stackp++)) -} - -__desc-head() -{ - local headi=$((__desc_stackp - 1)) - echo "${__desc_stack[ $headi ]}" -} - -__desc-headtype() -{ - local parts=( $(__desc-head) ) - echo "${parts[0]}" -} - -__desc-assert-within() -{ - local in="$1" - local chk="$2" - local line="$3" - local file="$4" - local phrase="${5:-be contained within}" - local head="$(__desc-headtype)" - local printin="$(__desc-type-clean "$in")" - - [ "$head" == "$in" ] \ - || bail "\`$chk' must $phrase \`$printin'; found \`$head' at $file:$line" -} - -__desc-type-clean() -{ - # a colon prefix is semantic; strip for display - echo "${1#:}" -} - -__desc-assert-follow() -{ - __desc-assert-within "$@" follow -} - - -begin-case() -{ - __desc_case="$1" -} - -tests() -{ - source ../src/"$1" -} - -describe() -{ - __desc-push "describe $(caller) $@" -} - -it() -{ - __desc-push "it $(caller) $@" -} - -end() -{ - local head="$(__desc-headtype)" - local cleanhead="$(__desc-type-clean "$head")" - - # some statements are implicitly terminated; explicitly doing so is - # indicitive of a syntax issue - [ "${head:0:1}" != : ] \ - || bail "unexpected \`end': still processing \`$cleanhead'" $(caller) - - __desc-pop || bail "unmatched \`end'" -} - -end-case() -{ - local tcase="$__desc_case" - __desc_case= - - # nothing to do if our stack is clean - [ "$__desc_stackp" -gt 0 ] || return 0 - - # output an error message for each item in the stack - while ((__desc_stackp--)); do - read type line file __ <<< "$(__desc-head)" - echo "error: $tcase: unterminated \`$type' at $file:$line" - done - - exit 1 -} - -bail() -{ - local msg="$1" - local line="$2" - local file="$3" - - echo -n "error: $1" >&2 - [ $# -gt 1 ] && echo -n " at $file:$line" >&2 - - echo - exit 1 -} - - -expect() -{ - __desc-assert-within it expect $(caller) - __desc_result="$($@ 2>"$__desc_errpath")" - __desc_rexit=$? - __desc-push ":expect $(caller) $@" -} - -to() -{ - __desc_caller=${__desc_caller:-$(caller)} - - [ $# -gt 0 ] || bail "missing assertion string for \`to'" $__desc_caller - - local type="$1" - shift - - __desc-assert-follow :expect to $(caller) - __desc-pop - - local assert="_desca-$type" - [ "$( type -t "$assert" )" == function ] \ - || bail "unknown \`to' assertion: \`$type'" $__desc_caller - - # invoke partially-applied assertion with remaining arguments - $assert "$@" || fail - __desc_caller= -} - -and() -{ - __desc_caller="$(caller)" - __desc-unpop - "$@" -} - - -# -# Assertions -# -_desca-succeed() -{ - __desca-exit -eq 0 -} - -_desca-fail() -{ - __desca-exit -ne 0 -} - -_desca-exit() -{ - __desca--argsep with 2 __desca-exit -eq -} - - -__desca-exit() -{ - __desca--argn 2 "$#" - [ "$__desc_rexit" "$@" ] -} - -_desca-output() -{ - local cmp="$1" - - diff="$( diff <( echo "$__desc_result" ) <( echo "$cmp" ) )" \ - && return 0 - - echo "$diff" >&2 - return 1 -} - -__desca--argsep() -{ - local delim="$1" - local cmdlen="$2" - local partial= - shift 2 - - # bash doesn't support multi-dimensional arrays, so here's to awkward command - # reconstruction with argument counts - while ((cmdlen--)); do - partial="$partial $1" - shift - done - - local next="$1" - shift - - [ "$next" == "$delim" ] \ - || bail "expected \`$delim' but found \`$next'" $__desc_caller - - $partial "$@" -} - -__desca--argn() -{ - [ $2 -eq "$1" ] || bail "invalid number of arguments" $__desc_caller -} - diff --git a/src/expect-core b/src/expect.sh similarity index 98% rename from src/expect-core rename to src/expect.sh index ee40002..2d44875 100644 --- a/src/expect-core +++ b/src/expect.sh @@ -22,7 +22,7 @@ [ -z $__INC_EXPECT_CORE ] || return __INC_EXPECT_CORE=1 -source expect/output +source expect/output.sh ## diff --git a/src/expect/output b/src/expect/output.sh similarity index 99% rename from src/expect/output rename to src/expect/output.sh index 58164c5..9cf8044 100644 --- a/src/expect/output +++ b/src/expect/output.sh @@ -22,7 +22,7 @@ [ -z $__INC_EXPECT_OUTPUT ] || return __INC_EXPECT_OUTPUT=1 -source util +source util.sh # reserved for our uses exec 99<>/dev/null diff --git a/src/run-spec b/src/run-spec index a21ac51..f050946 100755 --- a/src/run-spec +++ b/src/run-spec @@ -19,7 +19,7 @@ # along with this program. If not, see . ## -source spec +source spec.sh declare -r tcase="${1?Missing test case path}" diff --git a/src/spec b/src/spec.sh similarity index 99% rename from src/spec rename to src/spec.sh index 9913f11..16cce58 100644 --- a/src/spec +++ b/src/spec.sh @@ -29,8 +29,8 @@ [ -z $__INC_SPEC ] || return __INC_SPEC=1 -source specstack -source expect-core +source specstack.sh +source expect.sh # number of internal arguments before remainder clause declare -ir __SHIFTN=3 diff --git a/src/specstack b/src/specstack.sh similarity index 100% rename from src/specstack rename to src/specstack.sh diff --git a/src/util b/src/util.sh similarity index 100% rename from src/util rename to src/util.sh