@@ -16,6 +16,8 @@ let name_label = "name__label"
16
16
17
17
let name_description = " name__description"
18
18
19
+ let failwith_fmt fmt = Printf. ksprintf failwith fmt
20
+
19
21
module Tests =
20
22
functor
21
23
(Client : Db_interface.DB_ACCESS )
@@ -111,7 +113,7 @@ functor
111
113
; where_value= " "
112
114
}
113
115
in
114
- failwith ( Printf. sprintf " %s <invalid table>" fn_name)
116
+ failwith_fmt " %s <invalid table>" fn_name
115
117
) ;
116
118
Printf. printf
117
119
" %s <valid table> <invalid return> <valid field> <valid value>\n "
@@ -126,11 +128,9 @@ functor
126
128
; where_value= name
127
129
}
128
130
in
129
- failwith
130
- (Printf. sprintf
131
- " %s <valid table> <invalid return> <valid field> <valid value>"
132
- fn_name
133
- )
131
+ failwith_fmt
132
+ " %s <valid table> <invalid return> <valid field> <valid value>"
133
+ fn_name
134
134
) ;
135
135
Printf. printf
136
136
" %s <valid table> <valid return> <invalid field> <valid value>\n "
@@ -145,11 +145,9 @@ functor
145
145
; where_value= " "
146
146
}
147
147
in
148
- failwith
149
- (Printf. sprintf
150
- " %s <valid table> <valid return> <invalid field> <valid value>"
151
- fn_name
152
- )
148
+ failwith_fmt
149
+ " %s <valid table> <valid return> <invalid field> <valid value>"
150
+ fn_name
153
151
)
154
152
155
153
(* Verify the ref_index contents are correct for a given [tblname] and [key] (uuid/ref) *)
@@ -168,10 +166,9 @@ functor
168
166
| Some {Ref_index. name_label = name_label' ; uuid; _ref} ->
169
167
(* key should be either uuid or _ref *)
170
168
if key <> uuid && key <> _ref then
171
- failwith
172
- (Printf. sprintf " check_ref_index %s key %s: got ref %s uuid %s"
173
- tblname key _ref uuid
174
- ) ;
169
+ failwith_fmt " check_ref_index %s key %s: got ref %s uuid %s" tblname
170
+ key _ref uuid ;
171
+
175
172
let real_ref =
176
173
if Client. is_valid_ref t key then
177
174
key
@@ -183,14 +180,11 @@ functor
183
180
with _ -> None
184
181
in
185
182
if name_label' <> real_name_label then
186
- failwith
187
- (Printf. sprintf
188
- " check_ref_index %s key %s: ref_index name_label = %s; db has \
189
- %s"
190
- tblname key
191
- (Option. value ~default: " None" name_label')
192
- (Option. value ~default: " None" real_name_label)
193
- )
183
+ failwith_fmt
184
+ " check_ref_index %s key %s: ref_index name_label = %s; db has %s"
185
+ tblname key
186
+ (Option. value ~default: " None" name_label')
187
+ (Option. value ~default: " None" real_name_label)
194
188
195
189
open Db_cache_types
196
190
@@ -226,11 +220,9 @@ functor
226
220
in
227
221
let bar_foos = Row. find " foos" bar_1 in
228
222
if bar_foos <> Set [" foo:1" ] then
229
- failwith
230
- (Printf. sprintf
231
- " check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s"
232
- (Schema.Value. marshal bar_foos)
233
- ) ;
223
+ failwith_fmt
224
+ " check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s"
225
+ (Schema.Value. marshal bar_foos) ;
234
226
(* set foo.bars to [] *)
235
227
(* let foo_1 = Table.find "foo:1" (TableSet.find "foo" (Database.tableset db)) in*)
236
228
let db = set_field " foo" " foo:1" " bars" (Set [] ) db in
@@ -240,11 +232,8 @@ functor
240
232
in
241
233
let bar_foos = Row. find " foos" bar_1 in
242
234
if bar_foos <> Set [] then
243
- failwith
244
- (Printf. sprintf
245
- " check_many_to_many: bar(bar:1).foos expected () got %s"
246
- (Schema.Value. marshal bar_foos)
247
- ) ;
235
+ failwith_fmt " check_many_to_many: bar(bar:1).foos expected () got %s"
236
+ (Schema.Value. marshal bar_foos) ;
248
237
(* add 'bar' to foo.bars *)
249
238
let db = set_field " foo" " foo:1" " bars" (Set [" bar:1" ]) db in
250
239
(* check that 'bar.foos' includes 'foo' *)
@@ -253,11 +242,9 @@ functor
253
242
in
254
243
let bar_foos = Row. find " foos" bar_1 in
255
244
if bar_foos <> Set [" foo:1" ] then
256
- failwith
257
- (Printf. sprintf
258
- " check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s - 2"
259
- (Schema.Value. marshal bar_foos)
260
- ) ;
245
+ failwith_fmt
246
+ " check_many_to_many: bar(bar:1).foos expected ('foo:1') got %s - 2"
247
+ (Schema.Value. marshal bar_foos) ;
261
248
(* delete 'bar' *)
262
249
let db = remove_row " bar" " bar:1" db in
263
250
(* check that 'foo.bars' is empty *)
@@ -266,11 +253,8 @@ functor
266
253
in
267
254
let foo_bars = Row. find " bars" foo_1 in
268
255
if foo_bars <> Set [] then
269
- failwith
270
- (Printf. sprintf
271
- " check_many_to_many: foo(foo:1).foos expected () got %s"
272
- (Schema.Value. marshal foo_bars)
273
- ) ;
256
+ failwith_fmt " check_many_to_many: foo(foo:1).foos expected () got %s"
257
+ (Schema.Value. marshal foo_bars) ;
274
258
()
275
259
276
260
let check_events t =
@@ -503,8 +487,7 @@ functor
503
487
| None ->
504
488
Printf. printf " Reference '%s' has no associated table\n " invalid_ref
505
489
| Some t ->
506
- failwith
507
- (Printf. sprintf " Reference '%s' exists in table '%s'" invalid_ref t)
490
+ failwith_fmt " Reference '%s' exists in table '%s'" invalid_ref t
508
491
) ;
509
492
Printf. printf " is_valid_ref <invalid_ref>\n " ;
510
493
if Client. is_valid_ref t invalid_ref then
@@ -571,10 +554,8 @@ functor
571
554
Printf. printf " db_get_by_uuid <valid uuid>\n " ;
572
555
let r = Client. db_get_by_uuid t " VM" valid_uuid in
573
556
if r <> valid_ref then
574
- failwith
575
- (Printf. sprintf " db_get_by_uuid <valid uuid>: got %s; expected %s" r
576
- valid_ref
577
- ) ;
557
+ failwith_fmt " db_get_by_uuid <valid uuid>: got %s; expected %s" r
558
+ valid_ref ;
578
559
Printf. printf " db_get_by_uuid <invalid uuid>\n " ;
579
560
expect_missing_uuid " VM" invalid_uuid (fun () ->
580
561
let (_ : string ) = Client. db_get_by_uuid t " VM" invalid_uuid in
@@ -584,20 +565,14 @@ functor
584
565
let r = Client. db_get_by_uuid_opt t " VM" valid_uuid in
585
566
( if r <> Some valid_ref then
586
567
let rs = Option. value ~default: " None" r in
587
- failwith
588
- (Printf. sprintf
589
- " db_get_by_uuid_opt <valid uuid>: got %s; expected %s" rs
590
- valid_ref
591
- )
568
+ failwith_fmt " db_get_by_uuid_opt <valid uuid>: got %s; expected %s" rs
569
+ valid_ref
592
570
) ;
593
571
Printf. printf " db_get_by_uuid_opt <invalid uuid>\n " ;
594
572
let r = Client. db_get_by_uuid_opt t " VM" invalid_uuid in
595
573
if not (Option. is_none r) then
596
- failwith
597
- (Printf. sprintf
598
- " db_get_by_uuid_opt <invalid uuid>: got %s; expected None"
599
- valid_ref
600
- ) ;
574
+ failwith_fmt " db_get_by_uuid_opt <invalid uuid>: got %s; expected None"
575
+ valid_ref ;
601
576
Printf. printf " get_by_name_label <invalid name label>\n " ;
602
577
if Client. db_get_by_name_label t " VM" invalid_name <> [] then
603
578
failwith " db_get_by_name_label <invalid name label>" ;
0 commit comments