Changeset View
Standalone View
contrib/netbsd-tests/usr.bin/sort/t_sort.sh
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
atf_test_case empty_file | atf_test_case empty_file | ||||
empty_file_head() | empty_file_head() | ||||
{ | { | ||||
atf_set "descr" "Tests sorting an empty file" | atf_set "descr" "Tests sorting an empty file" | ||||
} | } | ||||
empty_file_body() | empty_file_body() | ||||
{ | { | ||||
touch empty | touch empty | ||||
atf_check -o empty sort -S empty | atf_check -o empty sort empty | ||||
atf_check sort -S -c empty | atf_check sort -c empty | ||||
atf_check sort -S -c -u empty | atf_check sort -c -u empty | ||||
} | } | ||||
atf_test_case end_of_options | atf_test_case end_of_options | ||||
end_of_options_head() | end_of_options_head() | ||||
{ | { | ||||
atf_set "descr" "Determination of end of option list" | atf_set "descr" "Determination of end of option list" | ||||
} | } | ||||
end_of_options_body() | end_of_options_body() | ||||
{ | { | ||||
echo x >-k | echo x >-k | ||||
atf_check -o file:-k -x "sort -S -- -k </dev/null" | atf_check -o file:-k -x "sort -- -k </dev/null" | ||||
atf_check -s not-exit:1 -e ignore -x "sort -S - -c </dev/null" | atf_check -s not-exit:1 -e ignore -x "sort - -c </dev/null" | ||||
} | } | ||||
atf_test_case missing_newline | atf_test_case missing_newline | ||||
missing_newline_head() | missing_newline_head() | ||||
{ | { | ||||
atf_set "descr" "Tests with missing new line in input file" | atf_set "descr" "Tests with missing new line in input file" | ||||
} | } | ||||
missing_newline_body() | missing_newline_body() | ||||
{ | { | ||||
printf '%s' x >in | printf '%s' x >in | ||||
atf_check -o inline:'x\n' sort in | atf_check -o inline:'x\n' sort in | ||||
} | } | ||||
atf_test_case null_bytes | atf_test_case null_bytes | ||||
null_bytes_head() | null_bytes_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the behavior of null bytes" | atf_set "descr" "Tests the behavior of null bytes" | ||||
} | } | ||||
null_bytes_body() | null_bytes_body() | ||||
{ | { | ||||
printf '\0b\n\0a\n' >in | printf '\0b\n\0a\n' >in | ||||
atf_check -o inline:'\0a\n\0b\n' sort -S in | atf_check -o inline:'\0a\n\0b\n' sort in | ||||
} | } | ||||
atf_test_case long_records | atf_test_case long_records | ||||
long_records_head() | long_records_head() | ||||
{ | { | ||||
atf_set "descr" "Tests long lines and keys" | atf_set "descr" "Tests long lines and keys" | ||||
} | } | ||||
long_records_body() | long_records_body() | ||||
Show All 16 Lines | |||||
long_file_head() | long_file_head() | ||||
{ | { | ||||
atf_set "descr" "Tests with a long file to try to force intermediate" \ | atf_set "descr" "Tests with a long file to try to force intermediate" \ | ||||
"files" | "files" | ||||
} | } | ||||
long_file_body() | long_file_body() | ||||
{ | { | ||||
awk 'BEGIN { for(i=0; i<20000; i++) print rand() }' >in | awk 'BEGIN { for(i=0; i<20000; i++) print rand() }' >in | ||||
sort -S -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out | sort -r in | awk '$0 "x" != x { print ; x = $0 "x" }' >out | ||||
atf_check -o file:out sort -u -r in | atf_check -o file:out sort -u -r in | ||||
} | } | ||||
atf_test_case any_char | atf_test_case any_char | ||||
any_char_head() | any_char_head() | ||||
{ | { | ||||
atf_set "descr" "Tests with files containing non-printable/extended" \ | atf_set "descr" "Tests with files containing non-printable/extended" \ | ||||
"characters" | "characters" | ||||
Show All 17 Lines | |||||
} | } | ||||
bflag_body() | bflag_body() | ||||
{ | { | ||||
cat >in <<EOF | cat >in <<EOF | ||||
b | b | ||||
a | a | ||||
EOF | EOF | ||||
atf_check -o file:in sort -b in | cat >expout <<EOF | ||||
atf_check -o file:in -x "sort -b <in" | a | ||||
b | |||||
EOF | |||||
atf_check -o file:expout sort -b in | |||||
atf_check -o file:expout -x "sort -b <in" | |||||
atf_check -s exit:1 -o ignore -e ignore -x "sort in | sort -c -r" | atf_check -s exit:1 -o ignore -e ignore -x "sort in | sort -c -r" | ||||
} | } | ||||
atf_test_case cflag | atf_test_case cflag | ||||
cflag_head() | cflag_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -c flag" | atf_set "descr" "Tests the -c flag" | ||||
} | } | ||||
cflag_body() | cflag_body() | ||||
{ | { | ||||
cat >in <<EOF | cat >in <<EOF | ||||
b | b | ||||
a | a | ||||
EOF | EOF | ||||
atf_check -s exit:1 -e ignore sort -S -c in | atf_check -s exit:1 -e ignore sort -c in | ||||
} | } | ||||
atf_test_case kflag_one_field | atf_test_case kflag_one_field | ||||
kflag_one_field_head() | kflag_one_field_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -k flag with one field" | atf_set "descr" "Tests the -k flag with one field" | ||||
} | } | ||||
kflag_one_field_body() | kflag_one_field_body() | ||||
Show All 30 Lines | |||||
EOF | EOF | ||||
cat >expout <<EOF | cat >expout <<EOF | ||||
x a n h | x a n h | ||||
x a n g | x a n g | ||||
z b m f | z b m f | ||||
y c o e | y c o e | ||||
EOF | EOF | ||||
atf_check -o file:expout sort -k2.1,2.0 in | atf_check -o file:expout sort -s -k2.1,2.0 in | ||||
} | } | ||||
atf_test_case kflag_many_fields | atf_test_case kflag_many_fields | ||||
kflag_many_fields_head() | kflag_many_fields_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -k flag with many fields" | atf_set "descr" "Tests the -k flag with many fields" | ||||
} | } | ||||
kflag_many_fields_body() | kflag_many_fields_body() | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | EOF | ||||
cat >out <<EOF | cat >out <<EOF | ||||
b 2 | b 2 | ||||
b 1 | b 1 | ||||
a 2 | a 2 | ||||
a 1 | a 1 | ||||
EOF | EOF | ||||
atf_check -o file:out sort -r -k1,1 -k2n in | atf_check -o file:out sort -r -k1,1 -k2nr in | ||||
markj: Please add a "On FreeBSD, ..." qualifier so that it's clear that this comment isn't from… | |||||
} | } | ||||
atf_test_case kflag_alpha | atf_test_case kflag_alpha | ||||
kflag_alpha_head() | kflag_alpha_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -k flag with various alpha fields" | atf_set "descr" "Tests the -k flag with various alpha fields" | ||||
} | } | ||||
kflag_alpha_body() | kflag_alpha_body() | ||||
Show All 20 Lines | |||||
19:10:09:11:09:15:07:11 ab | 19:10:09:11:09:15:07:11 ab | ||||
20:09:03:05:03:09:01:12 ab | 20:09:03:05:03:09:01:12 ab | ||||
21:20:23:17:23:05:23:17 ba | 21:20:23:17:23:05:23:17 ba | ||||
22:19:17:23:20:23:17:18 ba | 22:19:17:23:20:23:17:18 ba | ||||
23:18:11:13:11:17:11:19 ba | 23:18:11:13:11:17:11:19 ba | ||||
24:17:05:07:05:11:05:20 ba | 24:17:05:07:05:11:05:20 ba | ||||
EOF | EOF | ||||
atf_check -x "sort -S -k2b -k2 in >xx" | atf_check -x "sort -k2b -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k2n xx | atf_check -e ignore sort -c -t: -k2n xx | ||||
atf_check -x "sort -S -k2,2.1b -k2 in >xx" | atf_check -x "sort -k2,2.1b -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k3n xx | atf_check -e ignore sort -c -t: -k3n xx | ||||
atf_check -x "sort -S -k2.3 -k2 in >xx" | atf_check -x "sort -k2.3 -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k4n xx | atf_check -e ignore sort -c -t: -k4n xx | ||||
atf_check -x "sort -S -k2b,2.3 -k2 in >xx" | atf_check -x "sort -k2b,2.3 -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k5n xx | atf_check -e ignore sort -c -t: -k5n xx | ||||
atf_check -x "sort -S -k2.3,2.1b -k2 in >xx" | atf_check -x "sort -k2.3,2.1b -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k6n xx | atf_check -e ignore sort -c -t: -k6n xx | ||||
atf_check -x "sort -S -k2,2.1b -k2r in >xx" | atf_check -x "sort -k2,2.1b -k2r in >xx" | ||||
atf_check -e ignore sort -c -t: -k7n xx | atf_check -e ignore sort -c -t: -k7n xx | ||||
atf_check -x "sort -S -b -k2,2 -k2 in >xx" | atf_check -x "sort -b -k2,2 -k2 in >xx" | ||||
atf_check -e ignore sort -c -t: -k8n xx | atf_check -e ignore sort -c -t: -k8n xx | ||||
# XXX This test is broken. The standard is not clear on the behavior. | # XXX This test is broken. The standard is not clear on the behavior. | ||||
#atf_check -x "sort -S -b -k2,2b -k2 in >xx" | #atf_check -x "sort -S -b -k2,2b -k2 in >xx" | ||||
#atf_check -e ignore sort -c -t: -k3n xx | #atf_check -e ignore sort -c -t: -k3n xx | ||||
} | } | ||||
atf_test_case kflag_no_end | atf_test_case kflag_no_end | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
ab | ab | ||||
ab | ab | ||||
ac | ac | ||||
bc | bc | ||||
c | c | ||||
ca | ca | ||||
EOF | EOF | ||||
atf_check -o file:out sort -S -m in1 in2 | atf_check -o file:out sort -m in1 in2 | ||||
} | } | ||||
atf_test_case mflag_uflag | atf_test_case mflag_uflag | ||||
mflag_uflag_head() | mflag_uflag_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -m flag together with -u" | atf_set "descr" "Tests the -m flag together with -u" | ||||
} | } | ||||
mflag_uflag_body() | mflag_uflag_body() | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | |||||
atf_test_case oflag_displaced | atf_test_case oflag_displaced | ||||
oflag_displaced_head() | oflag_displaced_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -o flag after the file names" | atf_set "descr" "Tests the -o flag after the file names" | ||||
} | } | ||||
oflag_displaced_body() | oflag_displaced_body() | ||||
{ | { | ||||
atf_check sort -S /dev/null -o out | atf_check sort /dev/null -o out | ||||
test -f out || atf_fail "File not created" | test -f out || atf_fail "File not created" | ||||
} | } | ||||
atf_test_case rflag | atf_test_case rflag | ||||
rflag_head() | rflag_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -r flag" | atf_set "descr" "Tests the -r flag" | ||||
} | } | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | EOF | ||||
atf_check -o file:out sort -t ' ' -k2.1,2.0 in | atf_check -o file:out sort -t ' ' -k2.1,2.0 in | ||||
cat >out <<EOF | cat >out <<EOF | ||||
b c | b c | ||||
b c | b c | ||||
b c | b c | ||||
EOF | EOF | ||||
atf_check -o file:out sort -S -k2 in | atf_check -o file:out sort -k2 in | ||||
cat >out <<EOF | cat >out <<EOF | ||||
b c | b c | ||||
b c | b c | ||||
b c | b c | ||||
EOF | EOF | ||||
atf_check -o file:out sort -S -k2b in | atf_check -o file:out sort -k2b in | ||||
} | } | ||||
atf_test_case uflag | atf_test_case uflag | ||||
uflag_head() | uflag_head() | ||||
{ | { | ||||
atf_set "descr" "Tests the -u flag" | atf_set "descr" "Tests the -u flag" | ||||
} | } | ||||
uflag_body() | uflag_body() | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | EOF | ||||
cat >expout <<EOF | cat >expout <<EOF | ||||
x a n h | x a n h | ||||
x a n g | x a n g | ||||
z b m f | z b m f | ||||
y c o e | y c o e | ||||
EOF | EOF | ||||
atf_check -o file:expout sort +1 -2 in | atf_check -o file:expout sort -s +1 -2 in | ||||
} | } | ||||
atf_test_case plus_zero | atf_test_case plus_zero | ||||
plus_zero_head() | plus_zero_head() | ||||
{ | { | ||||
atf_set "descr" "Tests +- addressing: '-- +0' raised a '-k1.1: No" \ | atf_set "descr" "Tests +- addressing: '-- +0' raised a '-k1.1: No" \ | ||||
"such file or directory' error" | "such file or directory' error" | ||||
} | } | ||||
plus_zero_body() | plus_zero_body() | ||||
{ | { | ||||
echo 'good contents' >./+0 | echo 'good contents' >./+0 | ||||
atf_expect_fail "Bug 255798" | |||||
atf_check -o file:+0 sort -- +0 | atf_check -o file:+0 sort -- +0 | ||||
} | } | ||||
atf_test_case plus_nonmonotone | atf_test_case plus_nonmonotone | ||||
plus_nonmonotone_head() | plus_nonmonotone_head() | ||||
{ | { | ||||
atf_set "descr" "Tests += addressing: apparently nonmonotone field" \ | atf_set "descr" "Tests += addressing: apparently nonmonotone field" \ | ||||
"specs" | "specs" | ||||
} | } | ||||
plus_nonmonotone_body() | plus_nonmonotone_body() | ||||
{ | { | ||||
cat >in <<EOF | cat >in <<EOF | ||||
aaaa c | aaaa c | ||||
x a | x a | ||||
0 b | 0 b | ||||
EOF | EOF | ||||
atf_check -o file:in sort +1 -0.3 +1.4 -1.5 in | atf_check -o file:in sort +1 -0.3 +1.4 -1.5 in | ||||
} | } | ||||
atf_test_case plus_as_path | # Unclear if +0 is a valid position. | ||||
Not Done Inline ActionsThis actually looks the same as PR 255798? markj: This actually looks the same as PR 255798? | |||||
Done Inline ActionsFlags for sort can come after filenames; commands like sort in -r don't treat -r as a filename. Since +0 is a valid flag, then sort in +0 shouldn't take +0 as a filename in this case. cyril_freebsdfoundation.org: Flags for sort can come after filenames; commands like `sort in -r` don't treat `-r` as a… | |||||
Not Done Inline ActionsOof, that's weird. Looking at NetBSD's sort, they appear to stop mangling + options after encountering an option that doesn't start with - or +. We could perhaps implement that in D30234 as well. But our sort already behaves the same as GNU sort in this case, so it's probably better to keep things as they are. markj: Oof, that's weird. Looking at NetBSD's sort, they appear to stop mangling `+` options after… | |||||
plus_as_path_head() | # | ||||
{ | #atf_test_case plus_as_path | ||||
atf_set "descr" "Tests +- addressing: 'file +0' raised a '-k1.1: No" \ | #plus_as_path_head() | ||||
"such file or directory' error" | #{ | ||||
} | # atf_set "descr" "Tests +- addressing: 'file +0' raised a '-k1.1: No" \ | ||||
plus_as_path_body() | # "such file or directory' error" | ||||
{ | #} | ||||
echo 'good contents' >./+0 | #plus_as_path_body() | ||||
echo 'more contents' >in | #{ | ||||
cat ./+0 in >expout | # echo 'good contents' >./+0 | ||||
# echo 'more contents' >in | |||||
# cat ./+0 in >expout | |||||
# | |||||
# atf_check -o file:expout sort in +0 | |||||
#} | |||||
atf_check -o file:expout sort in +0 | |||||
} | |||||
atf_test_case plus_bad_tempfile | atf_test_case plus_bad_tempfile | ||||
plus_bad_tempfile_head() | plus_bad_tempfile_head() | ||||
{ | { | ||||
atf_set "descr" "Tests +- addressing: intermediate wrong behavior" \ | atf_set "descr" "Tests +- addressing: intermediate wrong behavior" \ | ||||
"that raised a '+0: No such file or directory' error" | "that raised a '+0: No such file or directory' error" | ||||
} | } | ||||
plus_bad_tempfile_body() | plus_bad_tempfile_body() | ||||
{ | { | ||||
echo 'good contents' >in | echo 'good contents' >in | ||||
atf_check -o file:in sort -T /tmp +0 in | atf_check -o file:in sort -T /tmp +0 in | ||||
} | } | ||||
atf_test_case plus_rflag_invalid | # Record separator option is not available. | ||||
plus_rflag_invalid_head() | # | ||||
{ | #atf_test_case plus_rflag_invalid | ||||
atf_set "descr" "Tests +- addressing: invalid record delimiter" | #plus_rflag_invalid_head() | ||||
} | #{ | ||||
plus_rflag_invalid_body() | # atf_set "descr" "Tests +- addressing: invalid record delimiter" | ||||
{ | #} | ||||
( | #plus_rflag_invalid_body() | ||||
echo 'z b m f' | #{ | ||||
echo 'y c o e' | # ( | ||||
markjUnsubmitted Not Done Inline ActionsRather than commenting out tests, it is better to add atf_skip calls at the beginning of each test. This reduces the number of local modifications to this file, which makes merging easier when changes are imported from NetBSD. markj: Rather than commenting out tests, it is better to add `atf_skip` calls at the beginning of each… | |||||
echo 'x a n h' | # echo 'z b m f' | ||||
echo 'x a n g' | # echo 'y c o e' | ||||
) | tr '\n' '+' >in | # echo 'x a n h' | ||||
# echo 'x a n g' | |||||
# ) | tr '\n' '+' >in | |||||
# | |||||
# atf_check -o inline:'x a n g+x a n h+z b m f+y c o e+' \ | |||||
# sort -R + -k2 in | |||||
#} | |||||
atf_check -o inline:'x a n g+x a n h+z b m f+y c o e+' \ | |||||
sort -R + -k2 in | |||||
} | |||||
atf_test_case plus_tflag | atf_test_case plus_tflag | ||||
plus_tflag_head() | plus_tflag_head() | ||||
{ | { | ||||
atf_set "descr" "Tests +- addressing: using -T caused a 'No such file" \ | atf_set "descr" "Tests +- addressing: using -T caused a 'No such file" \ | ||||
"or directory' error" | "or directory' error" | ||||
} | } | ||||
plus_tflag_body() | plus_tflag_body() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | atf_init_test_cases() | ||||
atf_add_test_case tflag_char_pos | atf_add_test_case tflag_char_pos | ||||
atf_add_test_case tflag_whitespace | atf_add_test_case tflag_whitespace | ||||
atf_add_test_case uflag | atf_add_test_case uflag | ||||
atf_add_test_case uflag_rflag | atf_add_test_case uflag_rflag | ||||
atf_add_test_case plus_one | atf_add_test_case plus_one | ||||
atf_add_test_case plus_one_minus_two | atf_add_test_case plus_one_minus_two | ||||
atf_add_test_case plus_zero | atf_add_test_case plus_zero | ||||
atf_add_test_case plus_nonmonotone | atf_add_test_case plus_nonmonotone | ||||
atf_add_test_case plus_as_path | # atf_add_test_case plus_as_path | ||||
atf_add_test_case plus_bad_tempfile | atf_add_test_case plus_bad_tempfile | ||||
atf_add_test_case plus_rflag_invalid | # atf_add_test_case plus_rflag_invalid | ||||
atf_add_test_case plus_tflag | atf_add_test_case plus_tflag | ||||
atf_add_test_case plus_no_end | atf_add_test_case plus_no_end | ||||
} | } |
Please add a "On FreeBSD, ..." qualifier so that it's clear that this comment isn't from upstream.