From fa29f36fe713a4bbdfca6770ebb3867436c1ac18 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sat, 4 Jun 2022 01:57:51 +0000 Subject: [PATCH] patch: add tests for our new patch program --- cmd/mkfile | 1 + cmd/patch/basic.expected | 100 ++++++++++++++++++++++++++++++++++ cmd/patch/basic.in | 93 +++++++++++++++++++++++++++++++ cmd/patch/basic.patch | 42 ++++++++++++++ cmd/patch/create.expected | 12 ++++ cmd/patch/create.patch | 15 +++++ cmd/patch/delete.expected | 10 ++++ cmd/patch/delete.patch | 15 +++++ cmd/patch/header.expected | 100 ++++++++++++++++++++++++++++++++++ cmd/patch/header.in | 93 +++++++++++++++++++++++++++++++ cmd/patch/header.patch | 54 ++++++++++++++++++ cmd/patch/mkfile | 5 ++ cmd/patch/multifile.patch | 89 ++++++++++++++++++++++++++++++ cmd/patch/multifile1.expected | 69 +++++++++++++++++++++++ cmd/patch/multifile1.in | 93 +++++++++++++++++++++++++++++++ cmd/patch/multifile2.expected | 19 +++++++ cmd/patch/multifile2.in | 21 +++++++ cmd/patch/nop.expected | 10 ++++ cmd/patch/patch.rc | 31 +++++++++++ 19 files changed, 872 insertions(+) create mode 100644 cmd/patch/basic.expected create mode 100644 cmd/patch/basic.in create mode 100644 cmd/patch/basic.patch create mode 100644 cmd/patch/create.expected create mode 100644 cmd/patch/create.patch create mode 100644 cmd/patch/delete.expected create mode 100644 cmd/patch/delete.patch create mode 100644 cmd/patch/header.expected create mode 100644 cmd/patch/header.in create mode 100644 cmd/patch/header.patch create mode 100644 cmd/patch/mkfile create mode 100644 cmd/patch/multifile.patch create mode 100644 cmd/patch/multifile1.expected create mode 100644 cmd/patch/multifile1.in create mode 100644 cmd/patch/multifile2.expected create mode 100644 cmd/patch/multifile2.in create mode 100644 cmd/patch/nop.expected create mode 100755 cmd/patch/patch.rc diff --git a/cmd/mkfile b/cmd/mkfile index 604a35a..4435395 100644 --- a/cmd/mkfile +++ b/cmd/mkfile @@ -4,6 +4,7 @@ TEST=\ cpp\ date\ git\ + patch\ test\ <../regress diff --git a/cmd/patch/basic.expected b/cmd/patch/basic.expected new file mode 100644 index 0000000..190423f --- /dev/null +++ b/cmd/patch/basic.expected @@ -0,0 +1,100 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 diff --git a/cmd/patch/basic.in b/cmd/patch/basic.in new file mode 100644 index 0000000..1f5a725 --- /dev/null +++ b/cmd/patch/basic.in @@ -0,0 +1,93 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/cmd/patch/basic.patch b/cmd/patch/basic.patch new file mode 100644 index 0000000..326d4cf --- /dev/null +++ b/cmd/patch/basic.patch @@ -0,0 +1,42 @@ +--- basic.in ++++ basic.out +@@ -1,3 +1,5 @@ ++1 ++2 + 3 + 4 + 5 +@@ -10,8 +12,8 @@ + 12 + 13 + 14 +-13 +-12 ++15 ++16 + 17 + 18 + 19 +@@ -35,6 +37,8 @@ + 37 + 38 + 39 ++40 ++41 + 42 + 43 + 44 +@@ -80,6 +84,7 @@ + 84 + 85 + 86 ++87 + 88 + 89 + 90 +@@ -91,3 +96,5 @@ + 96 + 97 + 98 ++99 ++100 diff --git a/cmd/patch/create.expected b/cmd/patch/create.expected new file mode 100644 index 0000000..08fe19c --- /dev/null +++ b/cmd/patch/create.expected @@ -0,0 +1,12 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 diff --git a/cmd/patch/create.patch b/cmd/patch/create.patch new file mode 100644 index 0000000..021c9d7 --- /dev/null +++ b/cmd/patch/create.patch @@ -0,0 +1,15 @@ +--- /dev/null ++++ create.out +@@ -1,0 +1,12 @@ ++1 ++2 ++3 ++4 ++5 ++6 ++7 ++8 ++9 ++10 ++11 ++12 diff --git a/cmd/patch/delete.expected b/cmd/patch/delete.expected new file mode 100644 index 0000000..f00c965 --- /dev/null +++ b/cmd/patch/delete.expected @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/cmd/patch/delete.patch b/cmd/patch/delete.patch new file mode 100644 index 0000000..2b6c1b5 --- /dev/null +++ b/cmd/patch/delete.patch @@ -0,0 +1,15 @@ +--- delete.out ++++ /dev/null +@@ -1,12 +1,0 @@ +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-11 +-12 diff --git a/cmd/patch/header.expected b/cmd/patch/header.expected new file mode 100644 index 0000000..190423f --- /dev/null +++ b/cmd/patch/header.expected @@ -0,0 +1,100 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 diff --git a/cmd/patch/header.in b/cmd/patch/header.in new file mode 100644 index 0000000..1f5a725 --- /dev/null +++ b/cmd/patch/header.in @@ -0,0 +1,93 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/cmd/patch/header.patch b/cmd/patch/header.patch new file mode 100644 index 0000000..b8ac887 --- /dev/null +++ b/cmd/patch/header.patch @@ -0,0 +1,54 @@ +diff should handle headers just fine, so +this file contains a few lines of header +and footer, with a couple of false starts, +consisting of lines starting with +--- some words +but no immediately following ++++ words +lines + +--- header.in ++++ header.out +@@ -1,3 +1,5 @@ ++1 ++2 + 3 + 4 + 5 +@@ -10,8 +12,8 @@ + 12 + 13 + 14 +-13 +-12 ++15 ++16 + 17 + 18 + 19 +@@ -35,6 +37,8 @@ + 37 + 38 + 39 ++40 ++41 + 42 + 43 + 44 +@@ -80,6 +84,7 @@ + 84 + 85 + 86 ++87 + 88 + 89 + 90 +@@ -91,3 +96,5 @@ + 96 + 97 + 98 ++99 ++100 +-- signature footer: should not get picked up +and here is the footer that should +also be ignored. diff --git a/cmd/patch/mkfile b/cmd/patch/mkfile new file mode 100644 index 0000000..0c754ae --- /dev/null +++ b/cmd/patch/mkfile @@ -0,0 +1,5 @@ +[2=1] echo fail: $1 $2 + >[2=1] diff -u $1 $2 + exit mismatch + } + status=() +} + +fn checkpatch{ + rm -f $1.out + patch $1.patch + check $1.out $1.expected +} + +checkpatch basic +checkpatch header +checkpatch create + +seq 12 > delete.out +patch delete.patch +test ! -f delete.out + +rm -f multifile^(1 2)^.out +patch multifile.patch +check multifile1.out multifile1.expected +check multifile2.out multifile2.expected + +status=() -- 2.45.2