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.

rberteig 2016-02-06 22:41 trunk
Commit c35152a5d47257cdaed94c52232392034a88cf1a
1 file changed +22 -12
+22 -12
--- test/json.test
+++ test/json.test
@@ -22,38 +22,48 @@
2222
# fossil. It looks like the one from tcllib is exactly what we need.
2323
# On ActiveTcl, add it with teacup. On other platforms, YMMV.
2424
# teacup install json
2525
# teacup install json::write
2626
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
+}
2736
2837
# Make sure we have a build with the json command at all and that it
2938
# is not stubbed out. This assumes the current (as of 2016-01-27)
3039
# practice of eliminating all trace of the fossil json command when
3140
# not configured. If that changes, these conditions might not prevent
3241
# the rest of this file from running.
3342
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
4045
}
4146
4247
# 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"}
4555
4656
# Use the CLI interface to execute a JSON command. Sets the global
4757
# RESULT to the response text, and JR to a Tcl dict conversion of the
4858
# response body.
4959
#
5060
# Returns "200" or "500".
5161
proc fossil_json {args} {
5262
global RESULT JR
5363
uplevel 1 fossil json {*}$args
54
- set JR [::json::json2dict $RESULT]
64
+ set JR [json2dict $RESULT]
5565
return "200"
5666
}
5767
5868
# Use the HTTP interface to GET a JSON API URL. Sets the globals
5969
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
@@ -65,11 +75,11 @@
6575
set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
6676
set RESULT [fossil_maybe_answer $request http {*}$args]
6777
regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
6878
regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
6979
if {$status eq "200"} {
70
- set JR [::json::json2dict $body]
80
+ set JR [json2dict $body]
7181
}
7282
return $status
7383
}
7484
7585
@@ -109,11 +119,11 @@
109119
# separate HTTP headers from body
110120
regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
111121
regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
112122
if {$status eq "200"} {
113123
if {[string length $body] > 0} {
114
- set JR [::json::json2dict $body]
124
+ set JR [json2dict $body]
115125
} else {
116126
set JR ""
117127
}
118128
}
119129
return $status
@@ -598,11 +608,11 @@
598608
test_json_envelope_ok json-wiki-diff-env
599609
test_json_payload json-wiki-diff [list v1 v2 diff] {}
600610
test json-wiki-diff-v1 {[dict get $JR payload v1] eq $uuid1}
601611
test json-wiki-diff-v1 {[dict get $JR payload v2] eq $uuid2}
602612
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}
604614
#puts [dict get $JR payload diff]
605615
606616
# wiki preview
607617
#
608618
# takes a string in fossil wiki markup and return an HTML fragment.
609619
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button