1# -*- tcl -*- 2# patch.test: tests for application of `diff -ruN` patches. 3 4# ------------------------------------------------------------------------- 5 6source [file join \ 7 [file dirname [file dirname [file join [pwd] [info script]]]] \ 8 devtools testutilities.tcl] 9 10testsNeedTcl 8.5 11testsNeedTcltest 2 12 13testing { 14 useLocal patch.tcl textutil::patch 15} 16 17# ------------------------------------------------------------------------- 18set m {wrong # args: should be "textutil::patch apply dir striplevel patch reportcmd"} 19 20test textutil-patch-1.0 {wrong args, not enough} -body { 21 textutil::patch apply 22} -returnCodes error -result $m 23 24test textutil-patch-1.1 {wrong args, not enough} -body { 25 textutil::patch apply D 26} -returnCodes error -result $m 27 28test textutil-patch-1.2 {wrong args, not enough} -body { 29 textutil::patch apply D S 30} -returnCodes error -result $m 31 32test textutil-patch-1.3 {wrong args, not enough} -body { 33 textutil::patch apply D S P 34} -returnCodes error -result $m 35 36test textutil-patch-1.4 {wrong args, too many} -body { 37 textutil::patch apply D S P R X 38} -returnCodes error -result $m 39 40unset m 41 42# ------------------------------------------------------------------------- 43## Patch application. All ok. 44 45proc setup-scratch {} { 46 # Create a temp directory hierarchy where we can perform patch application. 47 # scratch 48 # \- pkgIndex.tcl 49 50 file mkdir [asset scratch] 51 file copy [asset pkgIndex.tcl] [asset scratch/pkgIndex.tcl] 52 set ::trace {} 53 return 54} 55 56proc cleanup-scratch {} { 57 # Drop scratch area again. 58 unset ::trace 59 file delete -force [asset scratch] 60 return 61} 62 63proc record {args} { lappend ::trace $args } 64 65proc recorded {} { 66 lappend ::trace === [tcltest::viewFile [asset scratch/pkgIndex.tcl]] 67 join $::trace \n 68} 69 70foreach {tool striplevel} { 71 diff-ruN 1 72 git-diff 2 73 fossil-diff 2 74} { 75 incr k 76 test textutil-patch-2.$k "apply $tool" -setup { 77 setup-scratch 78 } -cleanup { 79 cleanup-scratch 80 } -body { 81 # Apply patch `pkgIndex.tcl.<tool>` to `scratch/pkgIndex.tcl`. 82 # The result should match `pkgIndex.tcl.patched`. 83 textutil::patch apply \ 84 [asset scratch] $striplevel \ 85 [asset-get pkgIndex.tcl.$tool] \ 86 record 87 recorded 88 } -result [join \ 89 [list \ 90 [list apply [asset scratch/pkgIndex.tcl]] \ 91 === \ 92 [tcltest::viewFile [asset pkgIndex.tcl.patched]]] \ 93 \n] 94} 95unset k 96 97catch { unset trace } 98rename setup-scratch {} 99rename cleanup-scratch {} 100 101# ------------------------------------------------------------------------- 102## Patch application. Trigger the various failures. TODO 103 104# ------------------------------------------------------------------------- 105 106testsuiteCleanup 107return 108