Index: etc/mtree/BSD.tests.dist =================================================================== --- etc/mtree/BSD.tests.dist +++ etc/mtree/BSD.tests.dist @@ -1102,6 +1102,8 @@ .. vmstat .. + wc + .. xargs .. xinstall Index: usr.bin/wc/Makefile =================================================================== --- usr.bin/wc/Makefile +++ usr.bin/wc/Makefile @@ -12,4 +12,7 @@ CFLAGS+=-DWITH_CASPER .endif +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include Index: usr.bin/wc/tests/01_longest_line.in =================================================================== --- /dev/null +++ usr.bin/wc/tests/01_longest_line.in @@ -0,0 +1,3 @@ +This is the testfile for testing the function of wc. +The following line are useless sentences. +amsvpasmvpasmvpom mak svp aslpv sakp vkowa ka sp aspk alk ko Index: usr.bin/wc/tests/02_new_lines.in =================================================================== --- /dev/null +++ usr.bin/wc/tests/02_new_lines.in @@ -0,0 +1,9 @@ + + + + + + + + + Index: usr.bin/wc/tests/03_tot_bytes.in =================================================================== --- /dev/null +++ usr.bin/wc/tests/03_tot_bytes.in @@ -0,0 +1,4 @@ +knasovnasokvnaso aps fnasoi fasoifcnas ncpasn ca +skan okcabs as fs +f as +f asokf a Index: usr.bin/wc/tests/04_zh-TW.in =================================================================== --- /dev/null +++ usr.bin/wc/tests/04_zh-TW.in @@ -0,0 +1 @@ +utf-8中文測試與位元數測試 Index: usr.bin/wc/tests/Makefile =================================================================== --- /dev/null +++ usr.bin/wc/tests/Makefile @@ -0,0 +1,12 @@ +# $FreebBSD$ + +PACKAGE= tests + +ATF_TESTS_SH= wc_test + +${PACKAGE}FILES+= 01_longest_line.in \ + 02_new_lines.in \ + 03_tot_bytes.in \ + 04_zh-TW.in + +.include Index: usr.bin/wc/tests/wc_test.sh =================================================================== --- /dev/null +++ usr.bin/wc/tests/wc_test.sh @@ -0,0 +1,83 @@ +#! /usr/libexec/atf-sh + +atf_test_case longestLine +longestLine_head() { + atf_set "descr" "Test the wc longest line output" \ + "with output -L" +} + +longestLine_body() { + atf_check -o inline:" 61 $(atf_get_srcdir)/01_longest_line.in\n" \ + wc -L $(atf_get_srcdir)/01_longest_line.in +} + +atf_test_case newLines +newLines_head() { + atf_set "descr" "Test the wc multiple blank newlines output" \ + "with output -l" +} + +newLines_body() { + atf_check -o inline:" 9 $(atf_get_srcdir)/02_new_lines.in\n" \ + wc -l $(atf_get_srcdir)/02_new_lines.in +} + +atf_test_case totalBytes +totalBytes_head() { + atf_set "descr" "Test with the wc byte count output" \ + "with output -c" +} + +totalBytes_body() { + atf_check -o inline:" $(stat -f %z $(atf_get_srcdir)/03_tot_bytes.in) $(atf_get_srcdir)/03_tot_bytes.in\n" wc -c $(atf_get_srcdir)/03_tot_bytes.in +} + +atf_test_case totalChars +totalChars_head() { + atf_set "descr" "Test with the wc char count output" \ + "with output -m" +} + +totalChars_body() { + atf_check -o inline:" 82 $(atf_get_srcdir)/03_tot_bytes.in\n" wc -m $(atf_get_srcdir)/03_tot_bytes.in +} + +atf_test_case totalZhBytes +totalZhBytes_head() { + atf_set "descr" "Test with the wc chinese byte count output" \ + "with output -c" +} + +totalZhBytes_body() { + atf_check -o inline:" 36 $(atf_get_srcdir)/04_zh-TW.in\n" wc -c $(atf_get_srcdir)/04_zh-TW.in +} + +atf_test_case totalZhChars +totalZhChars_head() { + atf_set "descr" "Test with the wc chinese char count output" \ + "with output -m" +} + +totalZhChars_body() { + atf_check -o inline:" 16 $(atf_get_srcdir)/04_zh-TW.in\n" sh -c "LC_ALL=zh_TW.UTF-8 wc -m $(atf_get_srcdir)/04_zh-TW.in" +} + +atf_test_case totalWords +totalWords_head() { + atf_set "descr" "Test with the wc word count output" \ + "with output -w" +} + +totalWords_body() { + atf_check -o inline:" 15 $(atf_get_srcdir)/03_tot_bytes.in\n" wc -w $(atf_get_srcdir)/03_tot_bytes.in +} + +atf_init_test_cases() { + atf_add_test_case longestLine + atf_add_test_case newLines + atf_add_test_case totalBytes + atf_add_test_case totalChars + atf_add_test_case totalWords + atf_add_test_case totalZhBytes + atf_add_test_case totalZhChars +}