Fossil SCM
Use the 'hasfeature' TH1 command to test if JSON was included at compile-time.
Commit
09a46c287359f04f74170571ea739d9d271e4b88
Parent
5d700c7d852ff11…
1 file changed
+15
-15
+15
-15
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -21,13 +21,14 @@ | ||
| 21 | 21 | # Make sure we have a build with the json command at all and that it |
| 22 | 22 | # is not stubbed out. This assumes the current (as of 2016-01-27) |
| 23 | 23 | # practice of eliminating all trace of the fossil json command when |
| 24 | 24 | # not configured. If that changes, these conditions might not prevent |
| 25 | 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 | |
| 26 | +fossil test-th-eval "hasfeature json" | |
| 27 | + | |
| 28 | +if {$::RESULT ne "1"} then { | |
| 29 | + puts "Fossil was not compiled with JSON support."; return | |
| 29 | 30 | } |
| 30 | 31 | |
| 31 | 32 | # We need a JSON parser to effectively test the JSON produced by |
| 32 | 33 | # fossil. It looks like the one from tcllib is exactly what we need. |
| 33 | 34 | # On ActiveTcl, add it with teacup. On other platforms, YMMV. |
| @@ -36,18 +37,18 @@ | ||
| 36 | 37 | package require json |
| 37 | 38 | |
| 38 | 39 | proc json2dict {txt} { |
| 39 | 40 | set rc [catch {::json::json2dict $txt} result options] |
| 40 | 41 | if {$rc != 0} { |
| 41 | - protOut "JSON ERROR: $result" | |
| 42 | + protOut "JSON ERROR: $result" | |
| 42 | 43 | return {} |
| 43 | 44 | } |
| 44 | 45 | return $result |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | # and that the json itself smells ok and has the expected API error code in it |
| 48 | -fossil json -expectError | |
| 49 | +fossil json -expectError | |
| 49 | 50 | set JR [json2dict $RESULT] |
| 50 | 51 | if {$JR eq ""} { |
| 51 | 52 | puts "Fossil was not compiled with JSON support (bad JSON)."; return |
| 52 | 53 | } |
| 53 | 54 | test json-1 {[dict exists $JR resultCode] |
| @@ -66,11 +67,11 @@ | ||
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | # Use the HTTP interface to GET a JSON API URL. Sets the globals |
| 69 | 70 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 70 | 71 | # the response body. |
| 71 | -# | |
| 72 | +# | |
| 72 | 73 | # Returns the status code from the HTTP header. |
| 73 | 74 | proc fossil_http_json {url {cookie "Muppet=Monster"} args} { |
| 74 | 75 | global RESULT JR |
| 75 | 76 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 76 | 77 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| @@ -87,11 +88,11 @@ | ||
| 87 | 88 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 88 | 89 | # the response body. |
| 89 | 90 | # |
| 90 | 91 | # Returns the status code from the HTTP header. |
| 91 | 92 | proc fossil_post_json {url data {cookie "Muppet=Monster"} args} { |
| 92 | - global RESULT JR | |
| 93 | + global RESULT JR | |
| 93 | 94 | |
| 94 | 95 | # set up a full GET or POST HTTP request |
| 95 | 96 | set len [string length $data] |
| 96 | 97 | if {$len > 0} { |
| 97 | 98 | set request [subst {POST $url HTTP/1.0\r |
| @@ -345,11 +346,11 @@ | ||
| 345 | 346 | |
| 346 | 347 | #### CONFIG |
| 347 | 348 | # json config get AREA |
| 348 | 349 | # AREAs are skin ticket project all skin-backup |
| 349 | 350 | foreach a [list skin ticket project all skin-backup] { |
| 350 | - fossil_json config get $a | |
| 351 | + fossil_json config get $a | |
| 351 | 352 | test_json_envelope_ok json-config-$a-env |
| 352 | 353 | # payload depends on specific area and may be completely empty |
| 353 | 354 | } |
| 354 | 355 | |
| 355 | 356 | #### DIFFS |
| @@ -384,11 +385,11 @@ | ||
| 384 | 385 | protOut [dict get $JR payload diff] |
| 385 | 386 | |
| 386 | 387 | |
| 387 | 388 | #### DIRECTORY LISTING |
| 388 | 389 | # json dir DIRNAME |
| 389 | -fossil_json dir | |
| 390 | +fossil_json dir | |
| 390 | 391 | test_json_envelope_ok json-dir-env |
| 391 | 392 | test_json_payload json-dir {name entries} {} |
| 392 | 393 | |
| 393 | 394 | #### FILE INFO |
| 394 | 395 | # json finfo FILENAME |
| @@ -526,11 +527,11 @@ | ||
| 526 | 527 | test_dict_keys json-user-list-$i $u {uid name capabilities info timestamp} {} |
| 527 | 528 | incr i |
| 528 | 529 | } |
| 529 | 530 | |
| 530 | 531 | # 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 | |
| 532 | 533 | test_json_envelope_ok json-user-save-env |
| 533 | 534 | test_json_payload json-user-save {uid name capabilities info timestamp} {} |
| 534 | 535 | |
| 535 | 536 | |
| 536 | 537 | # DOCBUG? Doc says payload is "same as /json/user/get" but actual |
| @@ -546,11 +547,11 @@ | ||
| 546 | 547 | |
| 547 | 548 | #### WIKI |
| 548 | 549 | |
| 549 | 550 | # wiki list |
| 550 | 551 | fossil_json wiki list |
| 551 | -test_json_envelope_ok json-wiki-list-env | |
| 552 | +test_json_envelope_ok json-wiki-list-env | |
| 552 | 553 | set pages [dict get $JR payload] |
| 553 | 554 | test json-wiki-1 {[llength $pages] == 1} |
| 554 | 555 | test json-wiki-2 {[lindex $pages 0] eq "Empty"} |
| 555 | 556 | fossil_json wiki list --verbose |
| 556 | 557 | set pages [dict get $JR payload] |
| @@ -557,11 +558,11 @@ | ||
| 557 | 558 | test json-wiki-verbose-1 {[llength $pages] == 1} |
| 558 | 559 | test_dict_keys json-wiki-verbose-pages [lindex $pages 0] [list name uuid user timestamp size] {} |
| 559 | 560 | |
| 560 | 561 | # wiki get |
| 561 | 562 | fossil_json wiki get Empty |
| 562 | -test_json_envelope_ok json-wiki-get-env | |
| 563 | +test_json_envelope_ok json-wiki-get-env | |
| 563 | 564 | # this page has only one version, so no parent should be listed |
| 564 | 565 | test_json_payload json-wiki-get [list name uuid user timestamp size content] [list parent] |
| 565 | 566 | |
| 566 | 567 | |
| 567 | 568 | # wiki create |
| @@ -663,11 +664,11 @@ | ||
| 663 | 664 | # HTML output. To reproduce: chmod 444 REPO, then submit a request |
| 664 | 665 | # which writes something (timeline creates a temp table). The "repo |
| 665 | 666 | # is not writable" error comes back as HTML. i don't know if the |
| 666 | 667 | # error happens before we have made the determination that the app is |
| 667 | 668 | # in JSON mode or if the error handling is incorrectly not |
| 668 | -# recognizing JSON mode. | |
| 669 | +# recognizing JSON mode. | |
| 669 | 670 | # |
| 670 | 671 | #repo_init x.fossil |
| 671 | 672 | #catch {exec chmod 444 .rep.fossil}; # Unix. What about Win? |
| 672 | 673 | fossil_http_json /json/timeline/checkin $U1Cookie |
| 673 | 674 | test json-ROrepo-1-1 {$CODE == 0} |
| @@ -685,11 +686,11 @@ | ||
| 685 | 686 | |
| 686 | 687 | |
| 687 | 688 | #### Result Codes |
| 688 | 689 | # Test cases designed to stimulate each (documented) error code. |
| 689 | 690 | |
| 690 | -# FOSSIL-0000 | |
| 691 | +# FOSSIL-0000 | |
| 691 | 692 | # Not returned by any command. We generally verify that in the |
| 692 | 693 | # test_json_envelope_ok command by verifying that the resultCode |
| 693 | 694 | # field is not present. Should any JSON endpoint begin to use the |
| 694 | 695 | # range reserved for non-fatal warnings, those tests will fail. |
| 695 | 696 | # |
| @@ -843,6 +844,5 @@ | ||
| 843 | 844 | # Fossil repository db file is not valid. |
| 844 | 845 | write_file nope.fossil { |
| 845 | 846 | This is not a fossil repo. It ought to be a SQLite db with a well-known schema, |
| 846 | 847 | but it is actually just a block of text. |
| 847 | 848 | } |
| 848 | - | |
| 849 | 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 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 |