Fossil SCM
Fixed json.test problem with fossil configured without --json. Removed the knownBug marker from the test json-wiki-diff-diff since [08197f96] fixed the bug it identified.
Commit
c35152a5d47257cdaed94c52232392034a88cf1a
Parent
25f7d3c1030fa4a…
1 file changed
+22
-12
+22
-12
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -22,38 +22,48 @@ | ||
| 22 | 22 | # fossil. It looks like the one from tcllib is exactly what we need. |
| 23 | 23 | # On ActiveTcl, add it with teacup. On other platforms, YMMV. |
| 24 | 24 | # teacup install json |
| 25 | 25 | # teacup install json::write |
| 26 | 26 | package require json |
| 27 | + | |
| 28 | +proc json2dict {txt} { | |
| 29 | + set rc [catch {::json::json2dict $txt} result options] | |
| 30 | + if {$rc != 0} { | |
| 31 | + protOut "JSON ERROR: $result" | |
| 32 | + return {} | |
| 33 | + } | |
| 34 | + return $result | |
| 35 | +} | |
| 27 | 36 | |
| 28 | 37 | # Make sure we have a build with the json command at all and that it |
| 29 | 38 | # is not stubbed out. This assumes the current (as of 2016-01-27) |
| 30 | 39 | # practice of eliminating all trace of the fossil json command when |
| 31 | 40 | # not configured. If that changes, these conditions might not prevent |
| 32 | 41 | # the rest of this file from running. |
| 33 | 42 | fossil help -a |
| 34 | -if {[string first json $RESULT] eq ""} { | |
| 35 | - puts "Fossil was not compiled with JSON support."; return | |
| 36 | -} | |
| 37 | -fossil json -expectError | |
| 38 | -if {$RESULT eq ""} { | |
| 39 | - puts "Fossil was not compiled with JSON support."; return | |
| 43 | +if {[string first json $RESULT] < 0} { | |
| 44 | + puts "Fossil was not compiled with JSON support (fossil help -a)."; return | |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | 47 | # and that the json itself smells ok and has the expected API error code in it |
| 43 | -set JR [::json::json2dict $RESULT] | |
| 44 | -test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"} | |
| 48 | +fossil json -expectError | |
| 49 | +set JR [json2dict $RESULT] | |
| 50 | +if {$JR eq ""} { | |
| 51 | + puts "Fossil was not compiled with JSON support (bad JSON)."; return | |
| 52 | +} | |
| 53 | +test json-1 {[dict exists $JR resultCode] | |
| 54 | + && [dict get $JR resultCode] eq "FOSSIL-4102"} | |
| 45 | 55 | |
| 46 | 56 | # Use the CLI interface to execute a JSON command. Sets the global |
| 47 | 57 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 48 | 58 | # response body. |
| 49 | 59 | # |
| 50 | 60 | # Returns "200" or "500". |
| 51 | 61 | proc fossil_json {args} { |
| 52 | 62 | global RESULT JR |
| 53 | 63 | uplevel 1 fossil json {*}$args |
| 54 | - set JR [::json::json2dict $RESULT] | |
| 64 | + set JR [json2dict $RESULT] | |
| 55 | 65 | return "200" |
| 56 | 66 | } |
| 57 | 67 | |
| 58 | 68 | # Use the HTTP interface to GET a JSON API URL. Sets the globals |
| 59 | 69 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| @@ -65,11 +75,11 @@ | ||
| 65 | 75 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 66 | 76 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 67 | 77 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 68 | 78 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 69 | 79 | if {$status eq "200"} { |
| 70 | - set JR [::json::json2dict $body] | |
| 80 | + set JR [json2dict $body] | |
| 71 | 81 | } |
| 72 | 82 | return $status |
| 73 | 83 | } |
| 74 | 84 | |
| 75 | 85 | |
| @@ -109,11 +119,11 @@ | ||
| 109 | 119 | # separate HTTP headers from body |
| 110 | 120 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 111 | 121 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 112 | 122 | if {$status eq "200"} { |
| 113 | 123 | if {[string length $body] > 0} { |
| 114 | - set JR [::json::json2dict $body] | |
| 124 | + set JR [json2dict $body] | |
| 115 | 125 | } else { |
| 116 | 126 | set JR "" |
| 117 | 127 | } |
| 118 | 128 | } |
| 119 | 129 | return $status |
| @@ -598,11 +608,11 @@ | ||
| 598 | 608 | test_json_envelope_ok json-wiki-diff-env |
| 599 | 609 | test_json_payload json-wiki-diff [list v1 v2 diff] {} |
| 600 | 610 | test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1} |
| 601 | 611 | test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2} |
| 602 | 612 | set diff [dict get $JR payload diff] |
| 603 | -test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} knownBug | |
| 613 | +test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} | |
| 604 | 614 | #puts [dict get $JR payload diff] |
| 605 | 615 | |
| 606 | 616 | # wiki preview |
| 607 | 617 | # |
| 608 | 618 | # takes a string in fossil wiki markup and return an HTML fragment. |
| 609 | 619 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -22,38 +22,48 @@ | |
| 22 | # fossil. It looks like the one from tcllib is exactly what we need. |
| 23 | # On ActiveTcl, add it with teacup. On other platforms, YMMV. |
| 24 | # teacup install json |
| 25 | # teacup install json::write |
| 26 | package require json |
| 27 | |
| 28 | # Make sure we have a build with the json command at all and that it |
| 29 | # is not stubbed out. This assumes the current (as of 2016-01-27) |
| 30 | # practice of eliminating all trace of the fossil json command when |
| 31 | # not configured. If that changes, these conditions might not prevent |
| 32 | # the rest of this file from running. |
| 33 | fossil help -a |
| 34 | if {[string first json $RESULT] eq ""} { |
| 35 | puts "Fossil was not compiled with JSON support."; return |
| 36 | } |
| 37 | fossil json -expectError |
| 38 | if {$RESULT eq ""} { |
| 39 | puts "Fossil was not compiled with JSON support."; return |
| 40 | } |
| 41 | |
| 42 | # and that the json itself smells ok and has the expected API error code in it |
| 43 | set JR [::json::json2dict $RESULT] |
| 44 | test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"} |
| 45 | |
| 46 | # Use the CLI interface to execute a JSON command. Sets the global |
| 47 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 48 | # response body. |
| 49 | # |
| 50 | # Returns "200" or "500". |
| 51 | proc fossil_json {args} { |
| 52 | global RESULT JR |
| 53 | uplevel 1 fossil json {*}$args |
| 54 | set JR [::json::json2dict $RESULT] |
| 55 | return "200" |
| 56 | } |
| 57 | |
| 58 | # Use the HTTP interface to GET a JSON API URL. Sets the globals |
| 59 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| @@ -65,11 +75,11 @@ | |
| 65 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 66 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 67 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 68 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 69 | if {$status eq "200"} { |
| 70 | set JR [::json::json2dict $body] |
| 71 | } |
| 72 | return $status |
| 73 | } |
| 74 | |
| 75 | |
| @@ -109,11 +119,11 @@ | |
| 109 | # separate HTTP headers from body |
| 110 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 111 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 112 | if {$status eq "200"} { |
| 113 | if {[string length $body] > 0} { |
| 114 | set JR [::json::json2dict $body] |
| 115 | } else { |
| 116 | set JR "" |
| 117 | } |
| 118 | } |
| 119 | return $status |
| @@ -598,11 +608,11 @@ | |
| 598 | test_json_envelope_ok json-wiki-diff-env |
| 599 | test_json_payload json-wiki-diff [list v1 v2 diff] {} |
| 600 | test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1} |
| 601 | test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2} |
| 602 | set diff [dict get $JR payload diff] |
| 603 | test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} knownBug |
| 604 | #puts [dict get $JR payload diff] |
| 605 | |
| 606 | # wiki preview |
| 607 | # |
| 608 | # takes a string in fossil wiki markup and return an HTML fragment. |
| 609 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -22,38 +22,48 @@ | |
| 22 | # fossil. It looks like the one from tcllib is exactly what we need. |
| 23 | # On ActiveTcl, add it with teacup. On other platforms, YMMV. |
| 24 | # teacup install json |
| 25 | # teacup install json::write |
| 26 | package require json |
| 27 | |
| 28 | proc json2dict {txt} { |
| 29 | set rc [catch {::json::json2dict $txt} result options] |
| 30 | if {$rc != 0} { |
| 31 | protOut "JSON ERROR: $result" |
| 32 | return {} |
| 33 | } |
| 34 | return $result |
| 35 | } |
| 36 | |
| 37 | # Make sure we have a build with the json command at all and that it |
| 38 | # is not stubbed out. This assumes the current (as of 2016-01-27) |
| 39 | # practice of eliminating all trace of the fossil json command when |
| 40 | # not configured. If that changes, these conditions might not prevent |
| 41 | # the rest of this file from running. |
| 42 | fossil help -a |
| 43 | if {[string first json $RESULT] < 0} { |
| 44 | puts "Fossil was not compiled with JSON support (fossil help -a)."; return |
| 45 | } |
| 46 | |
| 47 | # and that the json itself smells ok and has the expected API error code in it |
| 48 | fossil json -expectError |
| 49 | set JR [json2dict $RESULT] |
| 50 | if {$JR eq ""} { |
| 51 | puts "Fossil was not compiled with JSON support (bad JSON)."; return |
| 52 | } |
| 53 | test json-1 {[dict exists $JR resultCode] |
| 54 | && [dict get $JR resultCode] eq "FOSSIL-4102"} |
| 55 | |
| 56 | # Use the CLI interface to execute a JSON command. Sets the global |
| 57 | # RESULT to the response text, and JR to a Tcl dict conversion of the |
| 58 | # response body. |
| 59 | # |
| 60 | # Returns "200" or "500". |
| 61 | proc fossil_json {args} { |
| 62 | global RESULT JR |
| 63 | uplevel 1 fossil json {*}$args |
| 64 | set JR [json2dict $RESULT] |
| 65 | return "200" |
| 66 | } |
| 67 | |
| 68 | # Use the HTTP interface to GET a JSON API URL. Sets the globals |
| 69 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| @@ -65,11 +75,11 @@ | |
| 75 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 76 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 77 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 78 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 79 | if {$status eq "200"} { |
| 80 | set JR [json2dict $body] |
| 81 | } |
| 82 | return $status |
| 83 | } |
| 84 | |
| 85 | |
| @@ -109,11 +119,11 @@ | |
| 119 | # separate HTTP headers from body |
| 120 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 121 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 122 | if {$status eq "200"} { |
| 123 | if {[string length $body] > 0} { |
| 124 | set JR [json2dict $body] |
| 125 | } else { |
| 126 | set JR "" |
| 127 | } |
| 128 | } |
| 129 | return $status |
| @@ -598,11 +608,11 @@ | |
| 608 | test_json_envelope_ok json-wiki-diff-env |
| 609 | test_json_payload json-wiki-diff [list v1 v2 diff] {} |
| 610 | test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1} |
| 611 | test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2} |
| 612 | set diff [dict get $JR payload diff] |
| 613 | test json-wiki-diff-diff {[string first "+consectetur adipisicing elit" $diff] >= 0} |
| 614 | #puts [dict get $JR payload diff] |
| 615 | |
| 616 | # wiki preview |
| 617 | # |
| 618 | # takes a string in fossil wiki markup and return an HTML fragment. |
| 619 |