From a320badb3abe193baa202d522bd768a338cee403 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 22 Aug 2011 19:04:28 -0400 Subject: [PATCH] Began adding test scripts and inventory common --- items/.empty | 0 test/common | 33 +++++++++++++++++++++++++++++++++ test/test-common-inv | 37 +++++++++++++++++++++++++++++++++++++ util/common-inv | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 items/.empty create mode 100644 test/common create mode 100755 test/test-common-inv create mode 100644 util/common-inv diff --git a/items/.empty b/items/.empty new file mode 100644 index 0000000..e69de29 diff --git a/test/common b/test/common new file mode 100644 index 0000000..0d61ec2 --- /dev/null +++ b/test/common @@ -0,0 +1,33 @@ +#!/bin/bash + +lastgiven='' +lastexpected='' + +last() +{ + lastgiven="$1" + lastexpected="$2" +} + + +assert-equal() +{ + last "$1" "$2" + [ "$1" == "$2" ] +} + + +assert-eq() +{ + last "$1" "$2" + [ $1 -eq $2 ] +} + + +fail() +{ + echo "FAILURE: $1" >&2 + echo "Expected '$lastexpected', but received '$lastgiven'" >&2 + echo >&2 +} + diff --git a/test/test-common-inv b/test/test-common-inv new file mode 100755 index 0000000..0c1e4ad --- /dev/null +++ b/test/test-common-inv @@ -0,0 +1,37 @@ +#!/bin/bash + +mypath=$( dirname $0 ) +. "$mypath/common" +. "$mypath/../util/common-inv" + +#expected values +eid=_foo +ename="Large Ugly Foobar" +ecount=5 + +# test item tag +item="$ecount:$eid" + + +# let's write a temporary item for testing +itemfile="$mypath/../items/_foo" +cat > $itemfile <" + cat "$itemdir/$id" <<< "$1" \ + | grep '^NAME ' \ + | cut -d' ' -f2- +} + + +inv-item-id() +{ + cut -d':' -f2 <<< "$1" +} + + +inv-item-count() +{ + cut -d':' -f1 <<< "$1" +} +