| | @@ -1,36 +1,10 @@ |
| 1 | 1 | # |
| 2 | 2 | # Tests for 'fossil revert' |
| 3 | 3 | # |
| 4 | 4 | # |
| 5 | 5 | |
| 6 | | -catch {exec $::fossilexe info} res |
| 7 | | -puts res=$res |
| 8 | | -if {![regexp {use --repository} $res]} { |
| 9 | | - puts stderr "Cannot run this test within an open checkout" |
| 10 | | - return |
| 11 | | -} |
| 12 | | - |
| 13 | | -# Fossil will write data on $HOME, running 'fossil new' here. |
| 14 | | -# We need not to clutter the $HOME of the test caller. |
| 15 | | -# |
| 16 | | -set env(HOME) [pwd] |
| 17 | | - |
| 18 | | - |
| 19 | | -# Normalize file status lists (like those returned by 'fossil changes') |
| 20 | | -# so they can be compared using simple string comparison |
| 21 | | -# |
| 22 | | -proc normalize-status-list {list} { |
| 23 | | - set normalized [list] |
| 24 | | - set matches [regexp -all -inline -line {^\s*([A-Z]+)\s+(.*)$} $list] |
| 25 | | - foreach {_ status file} $matches { |
| 26 | | - lappend normalized [list $status [string trim $file]] |
| 27 | | - } |
| 28 | | - set normalized [lsort -index 1 $normalized] |
| 29 | | - return $normalized |
| 30 | | -} |
| 31 | | - |
| 32 | 6 | # Test 'fossil revert' against expected results from 'fossil changes' and |
| 33 | 7 | # 'fossil addremove --test', as well as by verifying the existence of files |
| 34 | 8 | # on the file system. 'fossil undo' is called after each test |
| 35 | 9 | # |
| 36 | 10 | proc revert-test {testid args} { |
| | @@ -49,17 +23,13 @@ |
| 49 | 23 | |
| 50 | 24 | fossil revert {*}$revertArgs |
| 51 | 25 | |
| 52 | 26 | set statusListTests [list -changes changes -addremove {addremove --test}] |
| 53 | 27 | foreach {key fossilArgs} $statusListTests { |
| 54 | | - set expected [normalize-status-list [dict get $args $key]] |
| 55 | | - set result [normalize-status-list [fossil {*}$fossilArgs]] |
| 56 | | - if {$result ne $expected} { |
| 57 | | - set passed 0 |
| 58 | | - protOut " Expected:\n [join $expected "\n "]" |
| 59 | | - protOut " Got:\n [join $result "\n "]" |
| 60 | | - } |
| 28 | + set expected [dict get $args $key] |
| 29 | + set result [fossil {*}$fossilArgs] |
| 30 | + test_status_list revert-$testid$key $result $expected |
| 61 | 31 | } |
| 62 | 32 | |
| 63 | 33 | set fileExistsTests [list -exists 1 does -notexists 0 should] |
| 64 | 34 | foreach {key expected verb} $fileExistsTests { |
| 65 | 35 | foreach path [dict get $args $key] { |
| | @@ -66,20 +36,17 @@ |
| 66 | 36 | if {[file exists $path] != $expected} { |
| 67 | 37 | set passed 0 |
| 68 | 38 | protOut " Failure: File $verb not exist: $path" |
| 69 | 39 | } |
| 70 | 40 | } |
| 41 | + test revert-$testid$key $passed |
| 71 | 42 | } |
| 72 | 43 | |
| 73 | 44 | fossil undo |
| 74 | | - test revert-$testid $passed |
| 75 | 45 | } |
| 76 | 46 | |
| 77 | | -# Create the repo |
| 78 | | -# |
| 79 | | -fossil new rep.fossil |
| 80 | | -fossil open rep.fossil |
| 47 | +repo_init |
| 81 | 48 | |
| 82 | 49 | # Prepare first commit |
| 83 | 50 | # |
| 84 | 51 | write_file f1 "f1" |
| 85 | 52 | write_file f2 "f2" |
| 86 | 53 | |