mirror of
https://github.com/sheumann/hush.git
synced 2024-08-14 11:28:58 +00:00
COMMAND=sort ./sort.tests So we can compare against non-busybox versions, and possibly our testsuite will be useful to somebody like the Linux Test Project someday. Redid testing.sh to add new command, "optional", to skip tests that require certain features. (use: `optional FEATURE_SORT_BIG`, or `optional ""` to stop skipping.) Note that optional is a NOP if the environment variable "OPTIONFLAGS" is blank, so although we're marking up the tests with busybox specific knowledge, it doesn't interfere with running the tests without busybox. Moved setting the "OPTIONFLAGS" environment variable to runtest. Philosophy: busybox-specific stuff belongs in runtest; both testing.sh and the tests themselves should be as busybox-agnostic as possible. Moved detecting that a command isn't in busybox at all (hence skipping the entire command.tests file) to runtests. Rationale: optional can't currently test for more than one feature at a time, so if we clear anything with optional "" we might perform tests we don't want to. Marked up busybox.tests to know which tests need CAT enabled. Fixed up other tests to be happy with new notation. I suspect egrep should be appended to grep. It's a sub-feature, really...
72 lines
2.2 KiB
Bash
Executable File
72 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# SUSv3 compliant uniq tests.
|
|
# Copyright 2005 by Rob Landley <rob@landley.net>
|
|
# Licensed under GPL v2, see file LICENSE for details.
|
|
|
|
# AUDIT: Full SUSv3 coverage (except internationalization).
|
|
|
|
if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
|
|
. testing.sh
|
|
|
|
# testing "test name" "options" "expected result" "file input" "stdin"
|
|
# file input will be file called "input"
|
|
# test can create a file "actual" instead of writing to stdout
|
|
|
|
# Test exit status
|
|
|
|
testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \
|
|
"yes\n" "" ""
|
|
testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" ""
|
|
|
|
# Test various data sources and destinations
|
|
|
|
testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
|
|
|
testing "uniq input outfile (two files)" "input actual > /dev/null" \
|
|
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
|
testing "uniq (stdin) outfile" "- actual" \
|
|
"one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
|
|
testing "uniq input - (specify stdout)" "input -" \
|
|
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
|
|
|
|
|
#-f skip fields
|
|
#-s skip chars
|
|
#-c occurrences
|
|
#-d dups only
|
|
#-u
|
|
|
|
# Test various command line options
|
|
|
|
# Leading whitespace is a minor technical violation of the spec,
|
|
# but since gnu does it...
|
|
testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \
|
|
"1 one\n2 two\n3 three\n" "" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
|
|
testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \
|
|
"cc dd ee8
|
|
aa bb cc9
|
|
" "" \
|
|
"cc dd ee8
|
|
bb cc dd8
|
|
aa bb cc9
|
|
"
|
|
|
|
# -d is "Suppress the writing fo lines that are not repeated in the input."
|
|
# -u is "Suppress the writing of lines that are repeated in the input."
|
|
# Therefore, together this means they should produce no output.
|
|
testing "uniq -u and -d produce no output" "-d -u" "" "" \
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
|
|
exit $FAILCOUNT
|