[Toybox] Test example: ls -b
Rob Landley
rob at landley.net
Tue Mar 15 01:24:28 PDT 2016
So I just checked in ls -b support, and improved -q to handle utf8
filenames, and testing it locally what I did was make a "utf8" directory
full of torture test files:
mkdir utf8
touch utf8/"$(cat toys/files/utf8/bad.txt)"
touch utf8/back\\slash
touch utf8/"$(cat toys/files/utf8/test1.txt)"
touch utf8/"$(echo -e "one\ntwo")" # bash can't tab complete this one
touch utf8/"$(cat toys/files/utf8/0xabad1dea.txt)"
touch utf8/"$(cat toys/files/utf8/japan.txt)"
I then got it to the point where:
$ diff -u <(ls -b utf8) <(./ls -b utf8)
$ diff -u <(ls -q utf8) <(./ls -q utf8)
Compared equal.
Turning that into proper test cases to go on the end of tests/ls.test is
nontrivial, and the kind of thing I throw on my todo list. Not exactly
_hard_, but a lot of work (time consuming) and at the moment I'm tired
from implementing -b (wrestling with it for a couple days to get it
right, wound up redoing the crunch_str() arguments several times). How
many individual tests should it be? How should the setup look? Should
creating the utf8 torture directory be factored out into a common shell
function so it can be reused elsewhere? (I've had that "utf8" directory
around locally for a while, I just worked out how to reproduce it above
but I accumulated it over a couple weeks going "ah, but does _this_
break it".)
Oh, locally that "one\ntwo" file is a shell script that calls "sleep
999" because I was testing how ps and top handled that. I've got another
executable with a ") " in it (not in that directory) because the
/proc/$$/stat field 2 "real name" has parentheses around it but the
_last_ parentheses is the end of the name, not the first, and I wanted
to make sure I was doing that right...
Anyway, I'm posting it here because of the recent test suite discussion.
Notice no mention of return codes in any of this, just input and output.
I got the behavior I wanted before checking the code in, but without the
tests I ran added to the test suite I can't ensure against regressions
next time I touch ls or crunch_str(), but the tests _I_ ran aren't
currently portable and depend on having ubuntu's implementation and mine
in the same path, meaning ubuntu could change something (or you could
run the test on red hat or buildroot) and get different behavior from
the host command which is _not_ a bug in my implementation. (Instance
testing "same" today != regression testing "correct" a year from now...)
Rob
More information about the Toybox
mailing list