Skip to content

Commit

Permalink
move print_value test to ensure no concurrency issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Destaq committed May 15, 2024
1 parent e69493b commit 5aa3273
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions test/test_sqaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,6 @@ let test_select_rows_nonexistent_table =
in
assert_raises (Failure "Table does not exist") select_rows)

(** [test_print_value] is an OUnit test that checks that [Sqaml.Row.print_value]
prints the correct representation of a value, for all value types. *)
let test_print_value =
as_test "test_print_value" (fun () ->
let output =
with_redirected_stdout (fun () -> Sqaml.Row.print_value (Int 5))
^ with_redirected_stdout (fun () -> Sqaml.Row.print_value (Float 4.5))
^ with_redirected_stdout (fun () ->
Sqaml.Row.print_value (Varchar "hello"))
^ with_redirected_stdout (fun () -> Sqaml.Row.print_value Null)
^ with_redirected_stdout (fun () ->
Sqaml.Row.print_value (Date "2022-12-12"))
in
assert_equal ~printer:printer_wrapper "5\n4.5\nhello\nnull\n2022-12-12\n"
output)

(** [test_value_equals] is an OUnit test that checks that [Sqaml.Row.value_equals]
returns the correct boolean value when comparing two values, for all supported value types. *)
let test_value_equals =
Expand Down Expand Up @@ -684,13 +668,27 @@ let test_parse_and_execute_query =
Sqaml.Parser.parse_and_execute_query "DROP TABLE users")
in
assert_equal ~printer:printer_wrapper "" output_drop;

let output_show =
with_redirected_stdout (fun () ->
Sqaml.Parser.parse_and_execute_query "SHOW TABLES")
in
assert_equal ~printer:printer_wrapper "No tables in database.\n"
output_show;

(* This check has been moved here due to concurrency issues. *)
let output_print_value =
with_redirected_stdout (fun () -> Sqaml.Row.print_value (Int 5))
^ with_redirected_stdout (fun () -> Sqaml.Row.print_value (Float 4.5))
^ with_redirected_stdout (fun () ->
Sqaml.Row.print_value (Varchar "hello"))
^ with_redirected_stdout (fun () -> Sqaml.Row.print_value Null)
^ with_redirected_stdout (fun () ->
Sqaml.Row.print_value (Date "2022-12-12"))
in
assert_equal ~printer:printer_wrapper "5\n4.5\nhello\nnull\n2022-12-12\n"
output_print_value;

create_tables ();
Sqaml.Database.insert_row "test_table"
[ "example"; "example2"; "example3"; "example4" ]
Expand Down Expand Up @@ -820,7 +818,6 @@ let suite =
test_print_nonexistent_table;
test_select_rows;
test_select_rows_nonexistent_table;
test_print_value;
test_value_equals;
test_value_less_than;
test_value_greater_than;
Expand Down

0 comments on commit 5aa3273

Please sign in to comment.