Fossil SCM

Use the 'hasfeature' TH1 command to test if JSON was included at compile-time.

mistachkin 2016-02-07 22:55 trunk
Commit 09a46c287359f04f74170571ea739d9d271e4b88
1 file changed +15 -15
+15 -15
--- test/json.test
+++ test/json.test
@@ -21,13 +21,14 @@
2121
# Make sure we have a build with the json command at all and that it
2222
# is not stubbed out. This assumes the current (as of 2016-01-27)
2323
# practice of eliminating all trace of the fossil json command when
2424
# not configured. If that changes, these conditions might not prevent
2525
# the rest of this file from running.
26
-fossil help -a
27
-if {[string first json $RESULT] < 0} {
28
- puts "Fossil was not compiled with JSON support (fossil help -a)."; return
26
+fossil test-th-eval "hasfeature json"
27
+
28
+if {$::RESULT ne "1"} then {
29
+ puts "Fossil was not compiled with JSON support."; return
2930
}
3031
3132
# We need a JSON parser to effectively test the JSON produced by
3233
# fossil. It looks like the one from tcllib is exactly what we need.
3334
# On ActiveTcl, add it with teacup. On other platforms, YMMV.
@@ -36,18 +37,18 @@
3637
package require json
3738
3839
proc json2dict {txt} {
3940
set rc [catch {::json::json2dict $txt} result options]
4041
if {$rc != 0} {
41
- protOut "JSON ERROR: $result"
42
+ protOut "JSON ERROR: $result"
4243
return {}
4344
}
4445
return $result
4546
}
4647
4748
# and that the json itself smells ok and has the expected API error code in it
48
-fossil json -expectError
49
+fossil json -expectError
4950
set JR [json2dict $RESULT]
5051
if {$JR eq ""} {
5152
puts "Fossil was not compiled with JSON support (bad JSON)."; return
5253
}
5354
test json-1 {[dict exists $JR resultCode]
@@ -66,11 +67,11 @@
6667
}
6768
6869
# Use the HTTP interface to GET a JSON API URL. Sets the globals
6970
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
7071
# the response body.
71
-#
72
+#
7273
# Returns the status code from the HTTP header.
7374
proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
7475
global RESULT JR
7576
set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
7677
set RESULT [fossil_maybe_answer $request http {*}$args]
@@ -87,11 +88,11 @@
8788
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
8889
# the response body.
8990
#
9091
# Returns the status code from the HTTP header.
9192
proc fossil_post_json {url data {cookie "Muppet=Monster"} args} {
92
- global RESULT JR
93
+ global RESULT JR
9394
9495
# set up a full GET or POST HTTP request
9596
set len [string length $data]
9697
if {$len > 0} {
9798
set request [subst {POST $url HTTP/1.0\r
@@ -345,11 +346,11 @@
345346
346347
#### CONFIG
347348
# json config get AREA
348349
# AREAs are skin ticket project all skin-backup
349350
foreach a [list skin ticket project all skin-backup] {
350
- fossil_json config get $a
351
+ fossil_json config get $a
351352
test_json_envelope_ok json-config-$a-env
352353
# payload depends on specific area and may be completely empty
353354
}
354355
355356
#### DIFFS
@@ -384,11 +385,11 @@
384385
protOut [dict get $JR payload diff]
385386
386387
387388
#### DIRECTORY LISTING
388389
# json dir DIRNAME
389
-fossil_json dir
390
+fossil_json dir
390391
test_json_envelope_ok json-dir-env
391392
test_json_payload json-dir {name entries} {}
392393
393394
#### FILE INFO
394395
# json finfo FILENAME
@@ -526,11 +527,11 @@
526527
test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
527528
incr i
528529
}
529530
530531
# json user save
531
-fossil_json user save --uid -1 --name U2 --password Utwo
532
+fossil_json user save --uid -1 --name U2 --password Utwo
532533
test_json_envelope_ok json-user-save-env
533534
test_json_payload json-user-save {uid name capabilities info timestamp} {}
534535
535536
536537
# DOCBUG? Doc says payload is "same as /json/user/get" but actual
@@ -546,11 +547,11 @@
546547
547548
#### WIKI
548549
549550
# wiki list
550551
fossil_json wiki list
551
-test_json_envelope_ok json-wiki-list-env
552
+test_json_envelope_ok json-wiki-list-env
552553
set pages [dict get $JR payload]
553554
test json-wiki-1 {[llength $pages] == 1}
554555
test json-wiki-2 {[lindex $pages 0] eq "Empty"}
555556
fossil_json wiki list --verbose
556557
set pages [dict get $JR payload]
@@ -557,11 +558,11 @@
557558
test json-wiki-verbose-1 {[llength $pages] == 1}
558559
test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {}
559560
560561
# wiki get
561562
fossil_json wiki get Empty
562
-test_json_envelope_ok json-wiki-get-env
563
+test_json_envelope_ok json-wiki-get-env
563564
# this page has only one version, so no parent should be listed
564565
test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent]
565566
566567
567568
# wiki create
@@ -663,11 +664,11 @@
663664
# HTML output. To reproduce: chmod 444 REPO, then submit a request
664665
# which writes something (timeline creates a temp table). The "repo
665666
# is not writable" error comes back as HTML. i don't know if the
666667
# error happens before we have made the determination that the app is
667668
# in JSON mode or if the error handling is incorrectly not
668
-# recognizing JSON mode.
669
+# recognizing JSON mode.
669670
#
670671
#repo_init x.fossil
671672
#catch {exec chmod 444 .rep.fossil}; # Unix. What about Win?
672673
fossil_http_json /json/timeline/checkin $U1Cookie
673674
test json-ROrepo-1-1 {$CODE == 0}
@@ -685,11 +686,11 @@
685686
686687
687688
#### Result Codes
688689
# Test cases designed to stimulate each (documented) error code.
689690
690
-# FOSSIL-0000
691
+# FOSSIL-0000
691692
# Not returned by any command. We generally verify that in the
692693
# test_json_envelope_ok command by verifying that the resultCode
693694
# field is not present. Should any JSON endpoint begin to use the
694695
# range reserved for non-fatal warnings, those tests will fail.
695696
#
@@ -843,6 +844,5 @@
843844
# Fossil repository db file is not valid.
844845
write_file nope.fossil {
845846
This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
846847
but it is actually just a block of text.
847848
}
848
-
849849
--- test/json.test
+++ test/json.test
@@ -21,13 +21,14 @@
21 # Make sure we have a build with the json command at all and that it
22 # is not stubbed out. This assumes the current (as of 2016-01-27)
23 # practice of eliminating all trace of the fossil json command when
24 # not configured. If that changes, these conditions might not prevent
25 # the rest of this file from running.
26 fossil help -a
27 if {[string first json $RESULT] < 0} {
28 puts "Fossil was not compiled with JSON support (fossil help -a)."; return
 
29 }
30
31 # We need a JSON parser to effectively test the JSON produced by
32 # fossil. It looks like the one from tcllib is exactly what we need.
33 # On ActiveTcl, add it with teacup. On other platforms, YMMV.
@@ -36,18 +37,18 @@
36 package require json
37
38 proc json2dict {txt} {
39 set rc [catch {::json::json2dict $txt} result options]
40 if {$rc != 0} {
41 protOut "JSON ERROR: $result"
42 return {}
43 }
44 return $result
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]
@@ -66,11 +67,11 @@
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
70 # the response body.
71 #
72 # Returns the status code from the HTTP header.
73 proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
74 global RESULT JR
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]
@@ -87,11 +88,11 @@
87 # RESULT to the HTTP response body, and JR to a Tcl dict conversion of
88 # the response body.
89 #
90 # Returns the status code from the HTTP header.
91 proc fossil_post_json {url data {cookie "Muppet=Monster"} args} {
92 global RESULT JR
93
94 # set up a full GET or POST HTTP request
95 set len [string length $data]
96 if {$len > 0} {
97 set request [subst {POST $url HTTP/1.0\r
@@ -345,11 +346,11 @@
345
346 #### CONFIG
347 # json config get AREA
348 # AREAs are skin ticket project all skin-backup
349 foreach a [list skin ticket project all skin-backup] {
350 fossil_json config get $a
351 test_json_envelope_ok json-config-$a-env
352 # payload depends on specific area and may be completely empty
353 }
354
355 #### DIFFS
@@ -384,11 +385,11 @@
384 protOut [dict get $JR payload diff]
385
386
387 #### DIRECTORY LISTING
388 # json dir DIRNAME
389 fossil_json dir
390 test_json_envelope_ok json-dir-env
391 test_json_payload json-dir {name entries} {}
392
393 #### FILE INFO
394 # json finfo FILENAME
@@ -526,11 +527,11 @@
526 test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
527 incr i
528 }
529
530 # json user save
531 fossil_json user save --uid -1 --name U2 --password Utwo
532 test_json_envelope_ok json-user-save-env
533 test_json_payload json-user-save {uid name capabilities info timestamp} {}
534
535
536 # DOCBUG? Doc says payload is "same as /json/user/get" but actual
@@ -546,11 +547,11 @@
546
547 #### WIKI
548
549 # wiki list
550 fossil_json wiki list
551 test_json_envelope_ok json-wiki-list-env
552 set pages [dict get $JR payload]
553 test json-wiki-1 {[llength $pages] == 1}
554 test json-wiki-2 {[lindex $pages 0] eq "Empty"}
555 fossil_json wiki list --verbose
556 set pages [dict get $JR payload]
@@ -557,11 +558,11 @@
557 test json-wiki-verbose-1 {[llength $pages] == 1}
558 test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {}
559
560 # wiki get
561 fossil_json wiki get Empty
562 test_json_envelope_ok json-wiki-get-env
563 # this page has only one version, so no parent should be listed
564 test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent]
565
566
567 # wiki create
@@ -663,11 +664,11 @@
663 # HTML output. To reproduce: chmod 444 REPO, then submit a request
664 # which writes something (timeline creates a temp table). The "repo
665 # is not writable" error comes back as HTML. i don't know if the
666 # error happens before we have made the determination that the app is
667 # in JSON mode or if the error handling is incorrectly not
668 # recognizing JSON mode.
669 #
670 #repo_init x.fossil
671 #catch {exec chmod 444 .rep.fossil}; # Unix. What about Win?
672 fossil_http_json /json/timeline/checkin $U1Cookie
673 test json-ROrepo-1-1 {$CODE == 0}
@@ -685,11 +686,11 @@
685
686
687 #### Result Codes
688 # Test cases designed to stimulate each (documented) error code.
689
690 # FOSSIL-0000
691 # Not returned by any command. We generally verify that in the
692 # test_json_envelope_ok command by verifying that the resultCode
693 # field is not present. Should any JSON endpoint begin to use the
694 # range reserved for non-fatal warnings, those tests will fail.
695 #
@@ -843,6 +844,5 @@
843 # Fossil repository db file is not valid.
844 write_file nope.fossil {
845 This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
846 but it is actually just a block of text.
847 }
848
849
--- test/json.test
+++ test/json.test
@@ -21,13 +21,14 @@
21 # Make sure we have a build with the json command at all and that it
22 # is not stubbed out. This assumes the current (as of 2016-01-27)
23 # practice of eliminating all trace of the fossil json command when
24 # not configured. If that changes, these conditions might not prevent
25 # the rest of this file from running.
26 fossil test-th-eval "hasfeature json"
27
28 if {$::RESULT ne "1"} then {
29 puts "Fossil was not compiled with JSON support."; return
30 }
31
32 # We need a JSON parser to effectively test the JSON produced by
33 # fossil. It looks like the one from tcllib is exactly what we need.
34 # On ActiveTcl, add it with teacup. On other platforms, YMMV.
@@ -36,18 +37,18 @@
37 package require json
38
39 proc json2dict {txt} {
40 set rc [catch {::json::json2dict $txt} result options]
41 if {$rc != 0} {
42 protOut "JSON ERROR: $result"
43 return {}
44 }
45 return $result
46 }
47
48 # and that the json itself smells ok and has the expected API error code in it
49 fossil json -expectError
50 set JR [json2dict $RESULT]
51 if {$JR eq ""} {
52 puts "Fossil was not compiled with JSON support (bad JSON)."; return
53 }
54 test json-1 {[dict exists $JR resultCode]
@@ -66,11 +67,11 @@
67 }
68
69 # Use the HTTP interface to GET a JSON API URL. Sets the globals
70 # RESULT to the HTTP response body, and JR to a Tcl dict conversion of
71 # the response body.
72 #
73 # Returns the status code from the HTTP header.
74 proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
75 global RESULT JR
76 set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
77 set RESULT [fossil_maybe_answer $request http {*}$args]
@@ -87,11 +88,11 @@
88 # RESULT to the HTTP response body, and JR to a Tcl dict conversion of
89 # the response body.
90 #
91 # Returns the status code from the HTTP header.
92 proc fossil_post_json {url data {cookie "Muppet=Monster"} args} {
93 global RESULT JR
94
95 # set up a full GET or POST HTTP request
96 set len [string length $data]
97 if {$len > 0} {
98 set request [subst {POST $url HTTP/1.0\r
@@ -345,11 +346,11 @@
346
347 #### CONFIG
348 # json config get AREA
349 # AREAs are skin ticket project all skin-backup
350 foreach a [list skin ticket project all skin-backup] {
351 fossil_json config get $a
352 test_json_envelope_ok json-config-$a-env
353 # payload depends on specific area and may be completely empty
354 }
355
356 #### DIFFS
@@ -384,11 +385,11 @@
385 protOut [dict get $JR payload diff]
386
387
388 #### DIRECTORY LISTING
389 # json dir DIRNAME
390 fossil_json dir
391 test_json_envelope_ok json-dir-env
392 test_json_payload json-dir {name entries} {}
393
394 #### FILE INFO
395 # json finfo FILENAME
@@ -526,11 +527,11 @@
527 test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {}
528 incr i
529 }
530
531 # json user save
532 fossil_json user save --uid -1 --name U2 --password Utwo
533 test_json_envelope_ok json-user-save-env
534 test_json_payload json-user-save {uid name capabilities info timestamp} {}
535
536
537 # DOCBUG? Doc says payload is "same as /json/user/get" but actual
@@ -546,11 +547,11 @@
547
548 #### WIKI
549
550 # wiki list
551 fossil_json wiki list
552 test_json_envelope_ok json-wiki-list-env
553 set pages [dict get $JR payload]
554 test json-wiki-1 {[llength $pages] == 1}
555 test json-wiki-2 {[lindex $pages 0] eq "Empty"}
556 fossil_json wiki list --verbose
557 set pages [dict get $JR payload]
@@ -557,11 +558,11 @@
558 test json-wiki-verbose-1 {[llength $pages] == 1}
559 test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {}
560
561 # wiki get
562 fossil_json wiki get Empty
563 test_json_envelope_ok json-wiki-get-env
564 # this page has only one version, so no parent should be listed
565 test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent]
566
567
568 # wiki create
@@ -663,11 +664,11 @@
664 # HTML output. To reproduce: chmod 444 REPO, then submit a request
665 # which writes something (timeline creates a temp table). The "repo
666 # is not writable" error comes back as HTML. i don't know if the
667 # error happens before we have made the determination that the app is
668 # in JSON mode or if the error handling is incorrectly not
669 # recognizing JSON mode.
670 #
671 #repo_init x.fossil
672 #catch {exec chmod 444 .rep.fossil}; # Unix. What about Win?
673 fossil_http_json /json/timeline/checkin $U1Cookie
674 test json-ROrepo-1-1 {$CODE == 0}
@@ -685,11 +686,11 @@
686
687
688 #### Result Codes
689 # Test cases designed to stimulate each (documented) error code.
690
691 # FOSSIL-0000
692 # Not returned by any command. We generally verify that in the
693 # test_json_envelope_ok command by verifying that the resultCode
694 # field is not present. Should any JSON endpoint begin to use the
695 # range reserved for non-fatal warnings, those tests will fail.
696 #
@@ -843,6 +844,5 @@
844 # Fossil repository db file is not valid.
845 write_file nope.fossil {
846 This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
847 but it is actually just a block of text.
848 }
 
849

Keyboard Shortcuts

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