#! ./tesh

p This tests whether TESH correctly sorts command output

$ ${bindir:=.}/tesh --enable-coverage --log='log.thresh:info tesh.fmt:%m%n' set-output-sort-1.tesh
> Enable coverage
> Test suite `set-output-sort-1'
> [set-output-sort-1:1] Test sorting and filtering of output
> [set-output-sort-1:3] true
> [set-output-sort-1:6] true
> [set-output-sort-1:8] printf 'profiling: foo\\n'
> [set-output-sort-1:10] printf 'profiling: foo'
> [set-output-sort-1:13] printf 'profiling: foo\\n'
> [set-output-sort-1:16] printf 'profiling: foo'
> [set-output-sort-1:18] printf 'a\\nb\\nc\\nd\\n'
> [set-output-sort-1:24] printf 'a\\nb\\nc\\nd'
> [set-output-sort-1:31] printf 'c\\nd\\nb\\na\\n'
> [set-output-sort-1:38] printf 'c\\nd\\nb\\na'
> [set-output-sort-1:44] printf 'a\\nprofiling: foo\\nprofiling: bar\\nb\\nc\\nd\\nprofiling: baz\\n'
> [set-output-sort-1:50] printf 'a\\nprofiling: foo\\nprofiling: bar\\nb\\nc\\nd\\nprofiling: baz'
> [set-output-sort-1:57] printf 'c\\nprofiling: foo\\nprofiling: bar\\nd\\nb\\na\\nprofiling: baz\\n'
> [set-output-sort-1:64] printf 'c\\nprofiling: foo\\nprofiling: bar\\nd\\nb\\na\\nprofiling: baz'
> Test suite `set-output-sort-1' OK

p Check the default prefix length (19) for "output sort"
! output sort
< 12345678901234567 B line
< 12345678901234567 A line
$ cat
> 12345678901234567 A line
> 12345678901234567 B line

! output sort
< 123456789012345678 B line
< 123456789012345678 A line
$ cat
> 123456789012345678 B line
> 123456789012345678 A line

! expect return 2
! output ignore
< ! output sort
< < 123456789012345678 B line
< < 123456789012345678 A line
< $ cat
< > 123456789012345678 A line
< > 123456789012345678 B line
$ ${bindir:=.}/tesh --enable-coverage

p Check user-defined prefix length for "output sort"
! output sort 5
< 000 B line
< 000 A line
$ cat
> 000 A line
> 000 B line

! output sort 4
< 000 B line
< 000 A line
$ cat
> 000 B line
> 000 A line

! expect return 2
! output ignore
< ! output sort 4
< < 000 B line
< < 000 A line
< $ cat
< > 000 A line
< > 000 B line
$ ${bindir:=.}/tesh --enable-coverage
