[Toybox] tail and trailing newlines

Elie De Brauwer eliedebrauwer at gmail.com
Thu Jul 5 14:08:01 PDT 2012


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 at lapedb:~/edb-stuff/toybox/toybox$ cat input
a
b
c
d
edb at 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 at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tail-trailing-newline.patch
Type: text/x-patch
Size: 1614 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20120705/cb6e0856/attachment-0006.bin>


More information about the Toybox mailing list