Fossil SCM

Clean up JSON tests and tweak use of catch in the test framework.

rberteig 2017-03-16 23:20 trunk
Commit 9e5f06deae5af2145a10a3343340818c11ab29aee7ef6306b11bd169624fb5b4
2 files changed +33 -10 +6
+33 -10
--- test/json.test
+++ test/json.test
@@ -133,10 +133,14 @@
133133
}
134134
135135
136136
# Inspect a dict for keys it must have and keys it must not have
137137
proc test_dict_keys {testname D okfields badfields} {
138
+ if {$D eq ""} {
139
+ test $testname-validJSON 0
140
+ return
141
+ }
138142
set i 1
139143
foreach f $okfields {
140144
test "$testname-$i" {[dict exists $D $f]}
141145
incr i
142146
}
@@ -742,24 +746,34 @@
742746
{
743747
"command":"no/such/endpoint"
744748
}
745749
}
746750
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 \
749753
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"}
751755
752756
753757
# FOSSIL-1103 FSL_JSON_E_UNKNOWN
754758
# Unknown error
755759
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
+}
761775
762776
# FOSSIL-1104 FSL_JSON_E_TIMEOUT
763777
# Timeout reached
764778
# FOSSIL-1105 FSL_JSON_E_ASSERT
765779
# Assertion failed
@@ -838,20 +852,29 @@
838852
# FOSSIL-4102 FSL_JSON_E_DB_NOT_FOUND
839853
# Fossil repository db file could not be found.
840854
fossil close
841855
fossil_json HAI -expectError
842856
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 \
844858
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"}
846860
fossil open .rep.fossil
847861
848862
# FOSSIL-4103 FSL_JSON_E_DB_NOT_VALID
849863
# Fossil repository db file is not valid.
850864
write_file nope.fossil {
851865
This is not a fossil repo. It ought to be a SQLite db with a well-known schema,
852866
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
853876
}
854877
855878
###############################################################################
856879
857880
test_cleanup
858881
--- 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
--- test/tester.tcl
+++ test/tester.tcl
@@ -113,10 +113,13 @@
113113
puts $out $msg
114114
close $out
115115
}
116116
}
117117
118
+# write a dict with just enough formatting
119
+# to make it human readable
120
+#
118121
proc protOutDict {dict {pattern *}} {
119122
set longest [tcl::mathfunc::max 0 {*}[lmap key [dict keys $dict $pattern] {string length $key}]]
120123
dict for {key value} $dict {
121124
protOut [format "%-${longest}s = %s" $key $value]
122125
}
@@ -974,12 +977,15 @@
974977
protInit $fossilexe
975978
set ::tempKeepHome 1
976979
foreach testfile $argv {
977980
protOut "***** $testfile ******"
978981
if { [catch {source $testdir/$testfile.test} testerror testopts] } {
982
+ test test-framework-$testfile 0
979983
protOut "!!!!! $testfile: $testerror"
980984
protOutDict $testopts"
985
+ } else {
986
+ test test-framework-$testfile 1
981987
}
982988
protOut "***** End of $testfile: [llength $bad_test] errors so far ******"
983989
}
984990
unset ::tempKeepHome; delete_temporary_home
985991
set nErr [llength $bad_test]
986992
--- 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

Keyboard Shortcuts

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