diff options
author | Bryan Drewery <bryan@shatow.net> | 2018-02-13 06:15:48 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2018-02-13 06:17:11 +0300 |
commit | 6267bd0dd4222e350965d187030c5259ce29e517 (patch) | |
tree | c782b4906cbf599be29f139815445379ca444baf /test | |
parent | 5c39e1f4cd10ea75cb4e7724c3a836f8b97304e8 (diff) |
Add read_file tests
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 1 | ||||
-rw-r--r-- | test/read_file.sh | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile index 706580d6..7a4d8cb7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,6 +7,7 @@ TESTS=\ locks_critical_section.sh \ locks_critical_section_nested.sh \ port_var_fetch.sh \ + read_file.sh \ relpath.sh \ relpath_common.sh \ shash_basic.sh \ diff --git a/test/read_file.sh b/test/read_file.sh new file mode 100644 index 00000000..19def1ae --- /dev/null +++ b/test/read_file.sh @@ -0,0 +1,31 @@ +#! /bin/sh + +. $(realpath $(dirname $0))/common.sh +. ${SCRIPTPREFIX}/include/util.sh + +TMP=$(mktemp -u) +data=blah +read_file data "${TMP}" 2>/dev/null +assert_not 0 $? "read_file on missing file should not return 0" +assert '' "${data}" "read_file on missing file should be blank" +assert 0 "${_read_file_lines_read}" "_read_file_lines_read should be 0 on missing file" + +echo "first" >> "${TMP}" +read_file data "${TMP}" +assert 'first' "${data}" "read_file on 1 line file should match" +assert 1 "${_read_file_lines_read}" "_read_file_lines_read should be 1" + +data=blah +echo "second" >> "${TMP}" +read_file data "${TMP}" +assert $'first\nsecond' "${data}" "read_file on 2 line file should match" +assert 2 "${_read_file_lines_read}" "_read_file_lines_read should be 1" + +data=blah +echo "third" >> "${TMP}" +read_file data "${TMP}" +assert $'first\nsecond\nthird' "${data}" "read_file on 3 line file should match" +assert 3 "${_read_file_lines_read}" "_read_file_lines_read should be 1" + +rm -f "${TMP}" +exit 0 |