. "$BST_LIB" # busybox ships no diffstat applet and there is no other diffstat on the image, # so a bare `diffstat` already is this port — no update-alternatives name to # disambiguate (unlike diff/patch/tar). require diffstat diffstat/present tmp=${TMPDIR:-/tmp}/bst-diffstat.$$ # A fixed unified diff — one file, 2 insertions, 1 deletion — so every expected # count below is a property of diffstat's parse, not of whichever diff produced # the input. Real diff output is covered separately at the end of this file. cat > "$tmp.one" <<'EOF' 2>/dev/null --- a/hello.c +++ b/hello.c @@ -1,3 +1,4 @@ line one -line two +line 2 line three +line four EOF # two files in one diff, 3 insertions / 2 deletions overall cat > "$tmp.two" <<'EOF' 2>/dev/null --- a/hello.c +++ b/hello.c @@ -1,3 +1,4 @@ line one -line two +line 2 line three +line four --- a/README +++ b/README @@ -1,2 +1,2 @@ title -old body +new body EOF check_out diffstat/version "diffstat version 1.66" diffstat -V # default report: the filename column, the scaled +/- histogram (3 changed # lines -> "++-"), and the git-style summary line. check_out diffstat/file-name "hello.c |" diffstat "$tmp.one" check_out diffstat/histogram "3 ++-" diffstat "$tmp.one" check_out diffstat/summary "1 file changed, 2 insertions(+), 1 deletion(-)" \ diffstat "$tmp.one" # with no filename argument diffstat reads the diff from stdin check_out diffstat/stdin "1 file changed" sh -c "diffstat < '$tmp.one'" # -t emits the counts as CSV: the header, then inserted,deleted,modified,name. check_out diffstat/csv-header "INSERTED,DELETED,MODIFIED,FILENAME" diffstat -t "$tmp.one" check_out diffstat/csv-counts '2,1,0,"hello.c"' diffstat -t "$tmp.one" # -l lists the affected filenames only, with no histogram or summary at all. check_eq diffstat/list-only "hello.c" "$(diffstat -l "$tmp.one" 2>&1)" # -m folds a matched insert/delete pair into one modification, so the same diff # reports 1 insertion + 1 modification instead of 2 insertions + 1 deletion. check_out diffstat/merged "1 insertion(+), 1 modification(!)" diffstat -m "$tmp.one" # a multi-file diff: both files are listed and the summary pluralises + totals. check_out diffstat/two-names "README" diffstat "$tmp.two" check_out diffstat/two-summary "2 files changed, 3 insertions(+), 2 deletions(-)" \ diffstat "$tmp.two" # an empty diff is not an error: diffstat says so and exits 0, and -q silences it. check_out diffstat/empty "0 files changed" sh -c ": | diffstat" check_eq diffstat/quiet "" "$(: | diffstat -q 2>&1)" # end to end on output a diff actually produced: busybox diff is always present # and its -u format is the same unified format. One changed line -> 1 insertion # and 1 deletion. diff exits 1 when files differ, so normalise that. printf 'alpha\nbeta\ngamma\n' > "$tmp.a" 2>/dev/null printf 'alpha\nBETA\ngamma\n' > "$tmp.b" 2>/dev/null busybox diff -u "$tmp.a" "$tmp.b" > "$tmp.d" 2>/dev/null; true check_out diffstat/real-diff "1 file changed, 1 insertion(+), 1 deletion(-)" \ diffstat "$tmp.d" rm -f "$tmp.one" "$tmp.two" "$tmp.a" "$tmp.b" "$tmp.d"