From 6b44a2456f9fb2fd60ff8aad4ced0c1e8f0a2937 Mon Sep 17 00:00:00 2001 From: Joan Font Date: Sat, 20 Aug 2016 20:02:32 +0200 Subject: [PATCH] Accept `length` parameter from stdin --- dick.sh | 8 +++++++- test.sh | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/dick.sh b/dick.sh index f8c10d6..b063efd 100755 --- a/dick.sh +++ b/dick.sh @@ -24,7 +24,13 @@ dick_usage() { " } -LENGTH=5 +read -t 0.01 STDIN_LENGTH +if [[ -n $STDIN_LENGTH ]]; then + LENGTH=$STDIN_LENGTH +else + LENGTH=5 +fi + SPERM=0 LAST_OPT="-l" NEW_LINE=1 diff --git a/test.sh b/test.sh index 9902cb2..787b719 100755 --- a/test.sh +++ b/test.sh @@ -35,6 +35,25 @@ test_output() { ok } +test_pipe() { + COMMAND="echo $1 | dick" + DICK="`echo $1 | dick`" + EXPECTED="$2" + + echo -ne " - '\e[1m$COMMAND\e[0m' should output '\e[1m$EXPECTED\e[0m'" + + if [[ "$?" != 0 ]]; then + fail "'$COMMAND' exit status was $?." + exit 1 + fi + + if [[ $DICK != $EXPECTED ]]; then + fail "Expected '$2', but got '$DICK'." + exit 1 + fi + ok +} + test_fails() { COMMAND="dick $1" @@ -64,6 +83,10 @@ test_output "-l 12 --sperm 0" "8============D" test_output "-v" "dick 0.2.0" test_output "--version" "dick 0.2.0" +test_pipe "10" "8==========D" +test_pipe "1" "8=D" +test_pipe "5" "8=====D" + test_fails '-p' test_fails '-q' test_fails '--length --s'