From 7b6a91422d020c432ed880083faafa3e433151e2 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Wed, 13 Sep 2023 22:46:53 +0100 Subject: [PATCH] Added size parsing test. --- tests/General_-_--size_argument_handling.test | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/General_-_--size_argument_handling.test diff --git a/tests/General_-_--size_argument_handling.test b/tests/General_-_--size_argument_handling.test new file mode 100755 index 0000000..80f0d9b --- /dev/null +++ b/tests/General_-_--size_argument_handling.test @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Check that size arguments are processed correctly. + +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}" + +# Pass size argument $1 and check that the last reported number is $2. +checkSizeArgument () { + reportedCount=$("${testSubject}" -XfnbSs "$1" /dev/zero 2>&1 | sed -n '$p' | tr -dc '0-9') + if ! test "${reportedCount}" = "$2"; then + echo "passed size argument $1, expected count of $2, but got ${reportedCount}" + exit 1 + fi +} + +checkSizeArgument 10000 10000 +checkSizeArgument 1k 1024 +checkSizeArgument 1M 1048576 +checkSizeArgument 8G 8589934592 + +exit 0 + +# EOF