toybox/tests/diff.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3#testing "name" "command" "result" "infile" "stdin"
   4
   5seq 10 > left
   6seq 11 > right
   7
   8testcmd "unknown argument" '--oops left right 2>/dev/null ; echo $?' "2\n" "" ""
   9testcmd "missing" 'missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
  10
  11testcmd "- -" '- - ; echo $?' "0\n" "" "whatever"
  12
  13testcmd "simple" "-u -L lll -L rrr left right" '--- lll
  14+++ rrr
  15@@ -8,3 +8,4 @@
  16 8
  17 9
  18 10
  19+11
  20' "" ""
  21
  22mkdir -p tree1 tree2
  23echo foo > tree1/file
  24echo food > tree2/file
  25
  26# Debian's diff gratuitously echoes its command line with -r. No idea why.
  27testcmd "-r" "-u -r -L tree1/file -L tree2/file tree1 tree2 | grep -v ^diff" \
  28  '--- tree1/file
  29+++ tree2/file
  30@@ -1 +1 @@
  31-foo
  32+food
  33' "" ""
  34
  35echo -e "hello\r\nworld\r\n"> a
  36echo -e "hello\nworld\n"> b
  37testcmd "--strip-trailing-cr off" "-q a b" "Files a and b differ\n" "" ""
  38testcmd "--strip-trailing-cr on" '-u --strip-trailing-cr a b; echo $?' \
  39  "0\n" "" ""
  40
  41echo -e "1\n2" > aa
  42echo -e "1\n3" > bb
  43testcmd "line format" "--unchanged-line-format=U%l --old-line-format=D%l --new-line-format=A%l aa bb" "U1D2A3" "" ""
  44testcmd "line format empty" "--unchanged-line-format= --old-line-format=D%l --new-line-format=A%l aa bb" "D2A3" "" ""
  45
  46mkfifo fifo1
  47mkfifo fifo2
  48echo -e "1\n2" > fifo1&
  49echo -e "1\n3" > fifo2&
  50testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1
  51+++ fifo2
  52@@ -1,2 +1,2 @@
  53 1
  54-2
  55+3
  56' "" ""
  57
  58seq 1 100000 > one
  59seq 1 4 100000 > two
  60testcmd 'big hunk' '-u --label nope --label nope one two' \
  61  "$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for((i=1;i<=100000;i++)); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' ''
  62rm one two
  63