Hello all,
In attachment a small patch. I touches two things (i can always split
the patch in two).
- first the make test stops running the tests after running the sort
test, maening it will not executed the tail, xargs, ... test. this
because the sort test contains an exit statement.
- next, i've spotted an error within tail, when tail reads input from
stdin and where the last character is not a newline (think echo -ne
"a\nb\nc", if you'd tail -n 1 this, you'd get b\nc while the output
should be just 'c'). Added a testcase and patch for this.
Next I encountered something odd which I really can't explain, so if
anybody can shed some light it would be appreciated, I was adding a
multiple input file test for tail, basically something like
testing "tail, multiple files" "tail -n 1 input input " "==> input
<==\nd\n\n==> input <==\nd\n" "a\nb\nc\nd\n" ""
When I execute this test from the commandline it runs fine:
edb@lapedb:~/edb-stuff/toybox/toybox$ cat input
a
b
c
d
edb@lapedb:~/edb-stuff/toybox/toybox$ ./toybox tail -n 1 input input
==> input <==
d
==> input <==
d
But when I modify the test above (which fails) to do tail -n 1 input
input | tee /tmp/log and look at the contents of /tmp/log, I get:
edb@lapedb:~/edb-stuff/toybox/toybox$ cat /tmp/log
d
d
==> input <==
==> input <==
Which is quite original, I think it must have something to do with i/o
buffering, but I have not succeed in reproducing it outside the
testscript (tee or > /tmp/log make no difference).
my 2 cents
E.
--
Elie De Brauwer
# HG changeset patch
# User Elie De Brauwer <[email protected]>
# Date 1341521908 -7200
# Node ID 8213890ae4b2902144e078dbdbe9b83b0c626928
# Parent e6acd7fbbfee3dea84aa44c0a9e34227cf70d6ef
- Do not abort testing after running the sort tests
- Add tail testcases for input not ending on a newline
- Fix condition where input coming from stdin does not have a trailing newline
diff -r e6acd7fbbfee -r 8213890ae4b2 scripts/test/sort.test
--- a/scripts/test/sort.test Sun Jul 01 23:48:15 2012 -0500
+++ b/scripts/test/sort.test Thu Jul 05 22:58:28 2012 +0200
@@ -97,4 +97,4 @@
"bork\nNaN\n-inf\n0.4\n1.222\n01.37\n2.1\n+infinity\n" "" \
"01.37\n1.222\n2.1\n0.4\nNaN\nbork\n-inf\n+infinity\n"
-exit $FAILCOUNT
+
diff -r e6acd7fbbfee -r 8213890ae4b2 scripts/test/tail.test
--- a/scripts/test/tail.test Sun Jul 01 23:48:15 2012 -0500
+++ b/scripts/test/tail.test Thu Jul 05 22:58:28 2012 +0200
@@ -22,6 +22,9 @@
testing "tail -c+ out of bonds" "tail -c +999 file1" "" "" ""
rm file1
+testing "tail stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc"
+testing "tail file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" ""
+
optional TAIL_SEEK
testing "tail noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \
"" "$BIGTEST"
diff -r e6acd7fbbfee -r 8213890ae4b2 toys/tail.c
--- a/toys/tail.c Sun Jul 01 23:48:15 2012 -0500
+++ b/toys/tail.c Thu Jul 05 22:58:28 2012 +0200
@@ -176,7 +176,7 @@
}
if (lines) {
- if(try[count] != '\n') continue;
+ if(try[count] != '\n' && count != len-1) continue;
if (lines<0) {
if (!++lines) ++lines;
continue;
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net