commit 0c9a7e9d9f2c0efc643a722ca46b8144fadf531f from: Stefan Sperling date: Wed Oct 07 22:21:17 2020 UTC add a zero-context test and rename the -C option to -U (matches diff(1)) commit - b6adedb6f92219b3795f616b46f18e752c5644be commit + 0c9a7e9d9f2c0efc643a722ca46b8144fadf531f blob - ff6ba3cd5842b83bb5c0d79e6b539956588d6cab blob + 1bf72dd40864c6752c57ff4ca4ff782b973d8768 --- diff/diff.c +++ diff/diff.c @@ -41,11 +41,12 @@ __dead void usage(void) { fprintf(stderr, - "usage: %s [-pw] [-C n] file1 file2\n" + "usage: %s [-pwe] [-U n] file1 file2\n" "\n" " -p Use Patience Diff (slower but often nicer)\n" " -w Ignore Whitespace\n" - " -C n Number of Context Lines\n" + " -U n Number of Context Lines\n" + " -e Produce ed script output\n" , getprogname()); exit(1); } @@ -57,7 +58,7 @@ main(int argc, char *argv[]) bool do_patience = false, ignore_whitespace = false; int context_lines = 3; - while ((ch = getopt(argc, argv, "pwC:")) != -1) { + while ((ch = getopt(argc, argv, "pwU:e")) != -1) { switch (ch) { case 'p': do_patience = true; @@ -65,7 +66,7 @@ main(int argc, char *argv[]) case 'w': ignore_whitespace = true; break; - case 'C': + case 'U': context_lines = atoi(optarg); break; default: blob - e3f7d395587ff642f388ff35f4d434f538f543aa blob + 9cd69d81128309347f230ac1951e7c0fdeb4683d --- test/verify_all.sh +++ test/verify_all.sh @@ -11,6 +11,11 @@ verify_diff_script() { expected_diff="$4" diff_opts="$5" + if echo -- $diff_opts | grep -q -- '-w'; then + ignore_whitespace="true" + else + ignore_whitespace="" + fi verify_left="verify.$orig_left" verify_right="verify.$orig_right" @@ -21,7 +26,7 @@ verify_diff_script() { return 1 fi fi - if [ -z "$diff_opts" -a "x$diff_type" = "xunidiff" ]; then + if [ -z "$ignore_whitespace" -a "x$diff_type" = "xunidiff" ]; then cp "$orig_left" "$verify_right" patch --quiet -u "$verify_right" "$the_diff" if ! cmp "$orig_right" "$verify_right" ; then @@ -35,7 +40,7 @@ verify_diff_script() { echo "FAIL: $orig_left != $verify_left" return 1 fi - elif [ -z "$diff_opts" ]; then + elif [ -z "$ignore_whitespace" ]; then tail -n +3 "$the_diff" | grep -v "^+" | sed 's/^.//' > "$verify_left" tail -n +3 "$the_diff" | grep -v "^-" | sed 's/^.//' > "$verify_right" @@ -54,7 +59,7 @@ verify_diff_script() { for left in test*.left* ; do right="$(echo "$left" | sed 's/\.left/\.right/')" - diff_opts="$(echo "$left" | sed 's/test[0-9]*\.left\([-a-zA-Z]*\).txt/\1/')" + diff_opts="$(echo "$left" | sed 's/test[0-9]*\.left\([-a-zA-Z0-9]*\).txt/\1/')" expected_diff="$(echo "$left" | sed 's/test\([-0-9a-zA-Z]*\)\..*/expect\1.diff/')" got_diff="verify.$expected_diff" blob - /dev/null blob + e622c0db8bdfc3b14ba0744767d678c901ed6c3d (mode 644) --- /dev/null +++ test/test017.left-U0.txt @@ -0,0 +1,15 @@ +a +x +x +x +x +x +x +x +x +x +x +f +g +h +j blob - /dev/null blob + 9495dcd762b8d50a725d011f44c48471a29146d4 (mode 644) --- /dev/null +++ test/test017.right-U0.txt @@ -0,0 +1,19 @@ +a +b +c +d +x +x +x +x +x +k +x +x +x +x +x +c +v +b +n