Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ dick_usage() {
"
}

LENGTH=5
read -t 0.01 STDIN_LENGTH
Copy link
Owner

@kaime kaime Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the timeout? Just tested without and tests passed smoothly on Ubuntu Xenial. Are you by any chance using an evil OS?

if [[ -n $STDIN_LENGTH ]]; then
LENGTH=$STDIN_LENGTH
else
LENGTH=5
fi

SPERM=0
LAST_OPT="-l"
NEW_LINE=1
Expand Down
23 changes: 23 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Copy link
Owner

@kaime kaime Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really like to "merge" this test_pipe() function with test_output(). Ie: add a stdio argument to test_output(). This way, we can document the behavior when both sttdin and a --lenght parameter is passed (which one takes precedence).

test_fails() {
COMMAND="dick $1"

Expand Down Expand Up @@ -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'
Expand Down