aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-11-05 19:09:15 -0600
committerRob Landley <rob@landley.net>2019-11-05 19:09:15 -0600
commit13468ca834b3ae6203541b44e1e2b2d7d86bb153 (patch)
tree233fc105b11e4862fff957d5fb789fe4357292a7
parenta0a51dee7cc2b39154f4272430a963f3ebbf222e (diff)
downloadtoybox-13468ca834b3ae6203541b44e1e2b2d7d86bb153.tar.gz
Switch -w tests to check boundary conditions, fix code to pass tests,
variable declarations go at the start of blocks, and remove specific people's names from todo items (anybody can do any todo).
-rwxr-xr-xtests/ls.test15
-rw-r--r--toys/posix/ls.c9
2 files changed, 15 insertions, 9 deletions
diff --git a/tests/ls.test b/tests/ls.test
index 33877aa2..c207c3f6 100755
--- a/tests/ls.test
+++ b/tests/ls.test
@@ -33,9 +33,6 @@ testing "with -k" "$IN && ls -k; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "
testing "with -m" "$IN && ls -m; $OUT" "dir1, dir2, file1.txt, file2.txt\n" "" ""
testing "with -F" "$IN && ls -F; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
testing "with -dk *" "$IN && ls -dk *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
-# TODO(ilijic) Remove `sed` commands in `-w` tests after trailing space patch is applied
-testing "with -w - one column" "$IN && ls -xw 5 | sed 's/^[ \t]*//;s/[ \t]*$//' && $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
-testing "with -w - two columns" "$IN && ls -Cw 32 | sed 's/^[ \t]*//;s/[ \t]*$//' && $OUT" "dir1 file1.txt\ndir2 file2.txt\n" "" ""
testing "with -Z" "$IN && ls -Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail; $OUT" "" "" ""
testing "with -lZ" "$IN && ls --full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail; $OUT" "" "" ""
@@ -60,5 +57,17 @@ unset INODE
testing "missing" "$IN && ls does-not-exist 2>err ; grep -q 'ls:.*missing.*: No
such file' err || echo missing error; $OUT" "" "" ""
+rm -f lstest/{file1.txt,err}
+touch lstest/{one,two,three,four,five,six,seven,eight,nine,ten}
+testing "-w test 1" "$IN && ls -Cw 20; $OUT" \
+ "eight one three\nfive seven two\nfour six\nnine ten\n" "" ""
+testing "-w test 2" "$IN && ls -Cw 19; $OUT" \
+ "eight seven\nfive six\nfour ten\nnine three\none two\n" "" ""
+
+rm -rf lstest/*
+touch lstest/{a,b,c,d,e,f}
+testing "-w test 3" "$IN && ls -Cw 3; $OUT" "a\nb\nc\nd\ne\nf\n" "" ""
+testing "-w test 4" "$IN && ls -Cw 4; $OUT" "a d\nb e\nc f\n" "" ""
+
# Removing test dir for cleanup purpose
rm -rf lstest
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index c7b09bf2..548a31a7 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -403,10 +403,9 @@ static void listfiles(int dirfd, struct dirtree *indir)
// Loop through again to produce output.
width = 0;
- unsigned curcol = 0;
for (ul = 0; ul<dtlen; ul++) {
int ii, zap;
- unsigned lastlen = *len, lastcol = curcol, color = 0;
+ unsigned curcol, lastlen = *len, lastcol = ul ? curcol : 0, color = 0;
unsigned long next = next_column(ul, dtlen, columns, &curcol);
struct stat *st = &(sort[next]->st);
mode_t mode = st->st_mode;
@@ -565,10 +564,8 @@ void ls_main(void)
}
TT.screen_width = 80;
- if (FLAG(w)) {
- // TODO (ilijic): Add test for setting w flag
- TT.screen_width = TT.w;
- } else { terminal_size(&TT.screen_width, NULL); }
+ if (FLAG(w)) TT.screen_width = TT.w+4;
+ else terminal_size(&TT.screen_width, NULL);
if (TT.screen_width<2) TT.screen_width = 2;
if (FLAG(b)) TT.escmore = " \\";