Fossil SCM
Fix TH1 'info exists' command for variables that have been unset.
Commit
7164f52baaae3e0ba307b66b377d3866e70f8905
Parent
da90bbe591a5355…
2 files changed
+2
-1
+25
M
src/th.c
+2
-1
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -1154,11 +1154,12 @@ | ||
| 1154 | 1154 | |
| 1155 | 1155 | /* |
| 1156 | 1156 | ** Return true if variable (zVar, nVar) exists. |
| 1157 | 1157 | */ |
| 1158 | 1158 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1159 | - return thFindValue(interp, zVar, nVar, 0, 0)!=0; | |
| 1159 | + Th_Variable *pValue = thFindValue(interp, zVar, nVar, 0, 0); | |
| 1160 | + return pValue && pValue->zData; | |
| 1160 | 1161 | } |
| 1161 | 1162 | |
| 1162 | 1163 | /* |
| 1163 | 1164 | ** String (zVar, nVar) must contain the name of a scalar variable or |
| 1164 | 1165 | ** array member. If the variable does not exist it is created. The |
| 1165 | 1166 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1154,11 +1154,12 @@ | |
| 1154 | |
| 1155 | /* |
| 1156 | ** Return true if variable (zVar, nVar) exists. |
| 1157 | */ |
| 1158 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1159 | return thFindValue(interp, zVar, nVar, 0, 0)!=0; |
| 1160 | } |
| 1161 | |
| 1162 | /* |
| 1163 | ** String (zVar, nVar) must contain the name of a scalar variable or |
| 1164 | ** array member. If the variable does not exist it is created. The |
| 1165 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1154,11 +1154,12 @@ | |
| 1154 | |
| 1155 | /* |
| 1156 | ** Return true if variable (zVar, nVar) exists. |
| 1157 | */ |
| 1158 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1159 | Th_Variable *pValue = thFindValue(interp, zVar, nVar, 0, 0); |
| 1160 | return pValue && pValue->zData; |
| 1161 | } |
| 1162 | |
| 1163 | /* |
| 1164 | ** String (zVar, nVar) must contain the name of a scalar variable or |
| 1165 | ** array member. If the variable does not exist it is created. The |
| 1166 |
+25
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -107,5 +107,30 @@ | ||
| 107 | 107 | ############################################################################### |
| 108 | 108 | |
| 109 | 109 | fossil test-th-eval "expr 42.0%0.0" |
| 110 | 110 | test th1-modulus-by-zero-4 {$RESULT eq \ |
| 111 | 111 | {TH_ERROR: expected integer, got: "42.0"}} |
| 112 | + | |
| 113 | +############################################################################### | |
| 114 | + | |
| 115 | +fossil test-th-eval "set var 1; info exists var" | |
| 116 | +test th1-info-exists-1 {$RESULT eq {1}} | |
| 117 | + | |
| 118 | +############################################################################### | |
| 119 | + | |
| 120 | +fossil test-th-eval "set var 1; unset var; info exists var" | |
| 121 | +test th1-info-exists-2 {$RESULT eq {0}} | |
| 122 | + | |
| 123 | +############################################################################### | |
| 124 | + | |
| 125 | +fossil test-th-eval "set var 1; unset var; set var 2; info exists var" | |
| 126 | +test th1-info-exists-3 {$RESULT eq {1}} | |
| 127 | + | |
| 128 | +############################################################################### | |
| 129 | + | |
| 130 | +fossil test-th-eval "set var 1; expr {\$var+0}" | |
| 131 | +test th1-info-exists-4 {$RESULT eq {1}} | |
| 132 | + | |
| 133 | +############################################################################### | |
| 134 | + | |
| 135 | +fossil test-th-eval "set var 1; unset var; expr {\$var+0}" | |
| 136 | +test th1-info-exists-5 {$RESULT eq {TH_ERROR: no such variable: var}} | |
| 112 | 137 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -107,5 +107,30 @@ | |
| 107 | ############################################################################### |
| 108 | |
| 109 | fossil test-th-eval "expr 42.0%0.0" |
| 110 | test th1-modulus-by-zero-4 {$RESULT eq \ |
| 111 | {TH_ERROR: expected integer, got: "42.0"}} |
| 112 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -107,5 +107,30 @@ | |
| 107 | ############################################################################### |
| 108 | |
| 109 | fossil test-th-eval "expr 42.0%0.0" |
| 110 | test th1-modulus-by-zero-4 {$RESULT eq \ |
| 111 | {TH_ERROR: expected integer, got: "42.0"}} |
| 112 | |
| 113 | ############################################################################### |
| 114 | |
| 115 | fossil test-th-eval "set var 1; info exists var" |
| 116 | test th1-info-exists-1 {$RESULT eq {1}} |
| 117 | |
| 118 | ############################################################################### |
| 119 | |
| 120 | fossil test-th-eval "set var 1; unset var; info exists var" |
| 121 | test th1-info-exists-2 {$RESULT eq {0}} |
| 122 | |
| 123 | ############################################################################### |
| 124 | |
| 125 | fossil test-th-eval "set var 1; unset var; set var 2; info exists var" |
| 126 | test th1-info-exists-3 {$RESULT eq {1}} |
| 127 | |
| 128 | ############################################################################### |
| 129 | |
| 130 | fossil test-th-eval "set var 1; expr {\$var+0}" |
| 131 | test th1-info-exists-4 {$RESULT eq {1}} |
| 132 | |
| 133 | ############################################################################### |
| 134 | |
| 135 | fossil test-th-eval "set var 1; unset var; expr {\$var+0}" |
| 136 | test th1-info-exists-5 {$RESULT eq {TH_ERROR: no such variable: var}} |
| 137 |