#!/bin/bash mypath=$( dirname $0 ) . "$mypath/common" add="$mypath/../util/inv-add" count="$mypath/../util/inv-count" # the item _foo does not exist $add 1:_foo 2>/dev/null && { simplefail "Should not be permitted to add unknown items to inventory" } # count should be 0 if we have none of the item in the inventory assert-equal $( $count _foo ) 0 || { fail "Should return 0 if item is not in inventory" } # let's create our dummy item itemfile="$mypath/../items/_foo" cat > "$itemfile" <<'EOF' NAME Test Foobar EOF # now, let's give that another shot. $add 1:_foo 2>/dev/null || { simplefail "Should be able to add item to inventory if it exists" } # one should have been added assert-equal $( $count _foo ) 1 || { fail "Should add item to inventory" } # number should be required $add _foo 2>/dev/null && { simplefail "Item quantity should be required" } # let's try adding another and ensure it's appended $add 1:_foo assert-equal $( $count _foo ) 2 || { fail "Items should be appended to inventory" } # now let's try to add multiple $add 2:_foo assert-equal $( $count _foo ) 4 || { fail "Should be able to add multiple items to inventory" } # we no longer need our test item rm "$itemfile"