Fossil SCM
Clean up JSON tests and tweak use of catch in the test framework.
Commit
9e5f06deae5af2145a10a3343340818c11ab29aee7ef6306b11bd169624fb5b4
Parent
b477fe57999e197…
2 files changed
+33
-10
+6
+33
-10
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -133,10 +133,14 @@ | ||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | # Inspect a dict for keys it must have and keys it must not have |
| 137 | 137 | proc test_dict_keys {testname D okfields badfields} { |
| 138 | + if {$D eq ""} { | |
| 139 | + test $testname-validJSON 0 | |
| 140 | + return | |
| 141 | + } | |
| 138 | 142 | set i 1 |
| 139 | 143 | foreach f $okfields { |
| 140 | 144 | test "$testname-$i" {[dict exists $D $f]} |
| 141 | 145 | incr i |
| 142 | 146 | } |
| @@ -742,24 +746,34 @@ | ||
| 742 | 746 | { |
| 743 | 747 | "command":"no/such/endpoint" |
| 744 | 748 | } |
| 745 | 749 | } |
| 746 | 750 | fossil_json --json-input e1102.json -expectError |
| 747 | -test json-env-RC-1102-CLI-exit {$CODE != 0} | |
| 748 | -test_json_envelope json-env-RC-1102-env {fossil timestamp command procTimeUs \ | |
| 751 | +test json-env-RC-1102a-CLI-exit {$CODE != 0} | |
| 752 | +test_json_envelope json-env-RC-1102a-env {fossil timestamp command procTimeUs \ | |
| 749 | 753 | procTimeMs resultCode resultText} {payload} |
| 750 | -test json-env-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"} | |
| 754 | +test json-env-RC-1102a-code {[dict get $JR resultCode] eq "FOSSIL-1102"} | |
| 751 | 755 | |
| 752 | 756 | |
| 753 | 757 | # FOSSIL-1103 FSL_JSON_E_UNKNOWN |
| 754 | 758 | # Unknown error |
| 755 | 759 | |
| 756 | -#write_file bad.sql { | |
| 757 | -#CREATE TABLE spam(a integer, b text); | |
| 758 | -#} | |
| 759 | -#exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql | |
| 760 | -#fossil_json HAI -R bad.fossil -expectError | |
| 760 | +write_file bad.sql { | |
| 761 | +CREATE TABLE spam(a integer, b text); | |
| 762 | +} | |
| 763 | +exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql | |
| 764 | +fossil_json HAI -R bad.fossil -expectError | |
| 765 | +test json-env-RC-1103-CLI-exit {$CODE != 0} | |
| 766 | +if { $JR ne "" } { | |
| 767 | + test_json_envelope json-env-RC-1103-env {fossil timestamp command procTimeUs \ | |
| 768 | + procTimeMs resultCode resultText} {payload} | |
| 769 | + test json-env-RC-1103-code {[dict exists $JR resultCode]\ | |
| 770 | + && [dict get $JR resultCode] eq "FOSSIL-1103"} knownBug | |
| 771 | +} else { | |
| 772 | + protOut "Want test case for FOSSIL-1103" | |
| 773 | + test json-RC-1103 0 knownBug | |
| 774 | +} | |
| 761 | 775 | |
| 762 | 776 | # FOSSIL-1104 FSL_JSON_E_TIMEOUT |
| 763 | 777 | # Timeout reached |
| 764 | 778 | # FOSSIL-1105 FSL_JSON_E_ASSERT |
| 765 | 779 | # Assertion failed |
| @@ -838,20 +852,29 @@ | ||
| 838 | 852 | # FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND |
| 839 | 853 | # Fossil repository db file could not be found. |
| 840 | 854 | fossil close |
| 841 | 855 | fossil_json HAI -expectError |
| 842 | 856 | test json-RC-4102-CLI-exit {$CODE != 0} |
| 843 | -test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \ | |
| 857 | +test_json_envelope json-RC-4102-CLI-exit {fossil timestamp command procTimeUs \ | |
| 844 | 858 | procTimeMs resultCode resultText} {payload} |
| 845 | -test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"} | |
| 859 | +test json-RC-4102 {[dict get $JR resultCode] eq "FOSSIL-4102"} | |
| 846 | 860 | fossil open .rep.fossil |
| 847 | 861 | |
| 848 | 862 | # FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID |
| 849 | 863 | # Fossil repository db file is not valid. |
| 850 | 864 | write_file nope.fossil { |
| 851 | 865 | This is not a fossil repo. It ought to be a SQLite db with a well-known schema, |
| 852 | 866 | but it is actually just a block of text. |
| 867 | +} | |
| 868 | +fossil_json HAI -R nope.fossil -expectError | |
| 869 | +test json-RC-4103-CLI-exit {$CODE != 0} | |
| 870 | +if { $JR ne "" } { | |
| 871 | + test_json_envelope json-RC-4103-CLI {fossil timestamp command procTimeUs \ | |
| 872 | + procTimeMs resultCode resultText} {payload} | |
| 873 | + test json-RC-4103 {[dict get $JR resultCode] eq "FOSSIL-4103"} | |
| 874 | +} else { | |
| 875 | + test json-RC-4103 0 knownBug | |
| 853 | 876 | } |
| 854 | 877 | |
| 855 | 878 | ############################################################################### |
| 856 | 879 | |
| 857 | 880 | test_cleanup |
| 858 | 881 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -133,10 +133,14 @@ | |
| 133 | } |
| 134 | |
| 135 | |
| 136 | # Inspect a dict for keys it must have and keys it must not have |
| 137 | proc test_dict_keys {testname D okfields badfields} { |
| 138 | set i 1 |
| 139 | foreach f $okfields { |
| 140 | test "$testname-$i" {[dict exists $D $f]} |
| 141 | incr i |
| 142 | } |
| @@ -742,24 +746,34 @@ | |
| 742 | { |
| 743 | "command":"no/such/endpoint" |
| 744 | } |
| 745 | } |
| 746 | fossil_json --json-input e1102.json -expectError |
| 747 | test json-env-RC-1102-CLI-exit {$CODE != 0} |
| 748 | test_json_envelope json-env-RC-1102-env {fossil timestamp command procTimeUs \ |
| 749 | procTimeMs resultCode resultText} {payload} |
| 750 | test json-env-RC-1102-code {[dict get $JR resultCode] eq "FOSSIL-1102"} |
| 751 | |
| 752 | |
| 753 | # FOSSIL-1103 FSL_JSON_E_UNKNOWN |
| 754 | # Unknown error |
| 755 | |
| 756 | #write_file bad.sql { |
| 757 | #CREATE TABLE spam(a integer, b text); |
| 758 | #} |
| 759 | #exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql |
| 760 | #fossil_json HAI -R bad.fossil -expectError |
| 761 | |
| 762 | # FOSSIL-1104 FSL_JSON_E_TIMEOUT |
| 763 | # Timeout reached |
| 764 | # FOSSIL-1105 FSL_JSON_E_ASSERT |
| 765 | # Assertion failed |
| @@ -838,20 +852,29 @@ | |
| 838 | # FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND |
| 839 | # Fossil repository db file could not be found. |
| 840 | fossil close |
| 841 | fossil_json HAI -expectError |
| 842 | test json-RC-4102-CLI-exit {$CODE != 0} |
| 843 | test_json_envelope json-RC-1102-env {fossil timestamp command procTimeUs \ |
| 844 | procTimeMs resultCode resultText} {payload} |
| 845 | test json-1 {[dict get $JR resultCode] eq "FOSSIL-4102"} |
| 846 | fossil open .rep.fossil |
| 847 | |
| 848 | # FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID |
| 849 | # Fossil repository db file is not valid. |
| 850 | write_file nope.fossil { |
| 851 | This is not a fossil repo. It ought to be a SQLite db with a well-known schema, |
| 852 | but it is actually just a block of text. |
| 853 | } |
| 854 | |
| 855 | ############################################################################### |
| 856 | |
| 857 | test_cleanup |
| 858 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -133,10 +133,14 @@ | |
| 133 | } |
| 134 | |
| 135 | |
| 136 | # Inspect a dict for keys it must have and keys it must not have |
| 137 | proc test_dict_keys {testname D okfields badfields} { |
| 138 | if {$D eq ""} { |
| 139 | test $testname-validJSON 0 |
| 140 | return |
| 141 | } |
| 142 | set i 1 |
| 143 | foreach f $okfields { |
| 144 | test "$testname-$i" {[dict exists $D $f]} |
| 145 | incr i |
| 146 | } |
| @@ -742,24 +746,34 @@ | |
| 746 | { |
| 747 | "command":"no/such/endpoint" |
| 748 | } |
| 749 | } |
| 750 | fossil_json --json-input e1102.json -expectError |
| 751 | test json-env-RC-1102a-CLI-exit {$CODE != 0} |
| 752 | test_json_envelope json-env-RC-1102a-env {fossil timestamp command procTimeUs \ |
| 753 | procTimeMs resultCode resultText} {payload} |
| 754 | test json-env-RC-1102a-code {[dict get $JR resultCode] eq "FOSSIL-1102"} |
| 755 | |
| 756 | |
| 757 | # FOSSIL-1103 FSL_JSON_E_UNKNOWN |
| 758 | # Unknown error |
| 759 | |
| 760 | write_file bad.sql { |
| 761 | CREATE TABLE spam(a integer, b text); |
| 762 | } |
| 763 | exec $::fossilexe sqlite3 --no-repository bad.fossil <bad.sql |
| 764 | fossil_json HAI -R bad.fossil -expectError |
| 765 | test json-env-RC-1103-CLI-exit {$CODE != 0} |
| 766 | if { $JR ne "" } { |
| 767 | test_json_envelope json-env-RC-1103-env {fossil timestamp command procTimeUs \ |
| 768 | procTimeMs resultCode resultText} {payload} |
| 769 | test json-env-RC-1103-code {[dict exists $JR resultCode]\ |
| 770 | && [dict get $JR resultCode] eq "FOSSIL-1103"} knownBug |
| 771 | } else { |
| 772 | protOut "Want test case for FOSSIL-1103" |
| 773 | test json-RC-1103 0 knownBug |
| 774 | } |
| 775 | |
| 776 | # FOSSIL-1104 FSL_JSON_E_TIMEOUT |
| 777 | # Timeout reached |
| 778 | # FOSSIL-1105 FSL_JSON_E_ASSERT |
| 779 | # Assertion failed |
| @@ -838,20 +852,29 @@ | |
| 852 | # FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND |
| 853 | # Fossil repository db file could not be found. |
| 854 | fossil close |
| 855 | fossil_json HAI -expectError |
| 856 | test json-RC-4102-CLI-exit {$CODE != 0} |
| 857 | test_json_envelope json-RC-4102-CLI-exit {fossil timestamp command procTimeUs \ |
| 858 | procTimeMs resultCode resultText} {payload} |
| 859 | test json-RC-4102 {[dict get $JR resultCode] eq "FOSSIL-4102"} |
| 860 | fossil open .rep.fossil |
| 861 | |
| 862 | # FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID |
| 863 | # Fossil repository db file is not valid. |
| 864 | write_file nope.fossil { |
| 865 | This is not a fossil repo. It ought to be a SQLite db with a well-known schema, |
| 866 | but it is actually just a block of text. |
| 867 | } |
| 868 | fossil_json HAI -R nope.fossil -expectError |
| 869 | test json-RC-4103-CLI-exit {$CODE != 0} |
| 870 | if { $JR ne "" } { |
| 871 | test_json_envelope json-RC-4103-CLI {fossil timestamp command procTimeUs \ |
| 872 | procTimeMs resultCode resultText} {payload} |
| 873 | test json-RC-4103 {[dict get $JR resultCode] eq "FOSSIL-4103"} |
| 874 | } else { |
| 875 | test json-RC-4103 0 knownBug |
| 876 | } |
| 877 | |
| 878 | ############################################################################### |
| 879 | |
| 880 | test_cleanup |
| 881 |
+6
| --- test/tester.tcl | ||
| +++ test/tester.tcl | ||
| @@ -113,10 +113,13 @@ | ||
| 113 | 113 | puts $out $msg |
| 114 | 114 | close $out |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | +# write a dict with just enough formatting | |
| 119 | +# to make it human readable | |
| 120 | +# | |
| 118 | 121 | proc protOutDict {dict {pattern *}} { |
| 119 | 122 | set longest [tcl::mathfunc::max 0 {*}[lmap key [dict keys $dict $pattern] {string length $key}]] |
| 120 | 123 | dict for {key value} $dict { |
| 121 | 124 | protOut [format "%-${longest}s = %s" $key $value] |
| 122 | 125 | } |
| @@ -974,12 +977,15 @@ | ||
| 974 | 977 | protInit $fossilexe |
| 975 | 978 | set ::tempKeepHome 1 |
| 976 | 979 | foreach testfile $argv { |
| 977 | 980 | protOut "***** $testfile ******" |
| 978 | 981 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 982 | + test test-framework-$testfile 0 | |
| 979 | 983 | protOut "!!!!! $testfile: $testerror" |
| 980 | 984 | protOutDict $testopts" |
| 985 | + } else { | |
| 986 | + test test-framework-$testfile 1 | |
| 981 | 987 | } |
| 982 | 988 | protOut "***** End of $testfile: [llength $bad_test] errors so far ******" |
| 983 | 989 | } |
| 984 | 990 | unset ::tempKeepHome; delete_temporary_home |
| 985 | 991 | set nErr [llength $bad_test] |
| 986 | 992 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -113,10 +113,13 @@ | |
| 113 | puts $out $msg |
| 114 | close $out |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | proc protOutDict {dict {pattern *}} { |
| 119 | set longest [tcl::mathfunc::max 0 {*}[lmap key [dict keys $dict $pattern] {string length $key}]] |
| 120 | dict for {key value} $dict { |
| 121 | protOut [format "%-${longest}s = %s" $key $value] |
| 122 | } |
| @@ -974,12 +977,15 @@ | |
| 974 | protInit $fossilexe |
| 975 | set ::tempKeepHome 1 |
| 976 | foreach testfile $argv { |
| 977 | protOut "***** $testfile ******" |
| 978 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 979 | protOut "!!!!! $testfile: $testerror" |
| 980 | protOutDict $testopts" |
| 981 | } |
| 982 | protOut "***** End of $testfile: [llength $bad_test] errors so far ******" |
| 983 | } |
| 984 | unset ::tempKeepHome; delete_temporary_home |
| 985 | set nErr [llength $bad_test] |
| 986 |
| --- test/tester.tcl | |
| +++ test/tester.tcl | |
| @@ -113,10 +113,13 @@ | |
| 113 | puts $out $msg |
| 114 | close $out |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | # write a dict with just enough formatting |
| 119 | # to make it human readable |
| 120 | # |
| 121 | proc protOutDict {dict {pattern *}} { |
| 122 | set longest [tcl::mathfunc::max 0 {*}[lmap key [dict keys $dict $pattern] {string length $key}]] |
| 123 | dict for {key value} $dict { |
| 124 | protOut [format "%-${longest}s = %s" $key $value] |
| 125 | } |
| @@ -974,12 +977,15 @@ | |
| 977 | protInit $fossilexe |
| 978 | set ::tempKeepHome 1 |
| 979 | foreach testfile $argv { |
| 980 | protOut "***** $testfile ******" |
| 981 | if { [catch {source $testdir/$testfile.test} testerror testopts] } { |
| 982 | test test-framework-$testfile 0 |
| 983 | protOut "!!!!! $testfile: $testerror" |
| 984 | protOutDict $testopts" |
| 985 | } else { |
| 986 | test test-framework-$testfile 1 |
| 987 | } |
| 988 | protOut "***** End of $testfile: [llength $bad_test] errors so far ******" |
| 989 | } |
| 990 | unset ::tempKeepHome; delete_temporary_home |
| 991 | set nErr [llength $bad_test] |
| 992 |