From 6065383e051e87c7e2be8d4f63dc03e9ac78bd79 Mon Sep 17 00:00:00 2001 From: Mahmoud Mandour Date: Fri, 17 Sep 2021 20:35:55 +0200 Subject: LibSQL: Check NoError individually in execution tests This enables tests to check that a statement is erroneous, we could not do so by only calling `execute()` since it asserted that no errors occurred. --- Tests/LibSQL/TestSqlStatementExecution.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Tests') diff --git a/Tests/LibSQL/TestSqlStatementExecution.cpp b/Tests/LibSQL/TestSqlStatementExecution.cpp index 4f202b1270..28169553c5 100644 --- a/Tests/LibSQL/TestSqlStatementExecution.cpp +++ b/Tests/LibSQL/TestSqlStatementExecution.cpp @@ -28,13 +28,13 @@ RefPtr execute(NonnullRefPtr database, String con } SQL::AST::ExecutionContext context { database }; auto result = statement->execute(context); - EXPECT(result->error().code == SQL::SQLErrorCode::NoError); return result; } void create_schema(NonnullRefPtr database) { auto result = execute(database, "CREATE SCHEMA TestSchema;"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 1); } @@ -42,6 +42,7 @@ void create_table(NonnullRefPtr database) { create_schema(database); auto result = execute(database, "CREATE TABLE TestSchema.TestTable ( TextColumn text, IntColumn integer );"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 1); } @@ -69,6 +70,7 @@ TEST_CASE(insert_into_table) auto database = SQL::Database::construct(db_name); create_table(database); auto result = execute(database, "INSERT INTO TestSchema.TestTable ( TextColumn, IntColumn ) VALUES ( 'Test', 42 );"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 1); auto table = database->get_table("TESTSCHEMA", "TESTTABLE"); @@ -88,12 +90,16 @@ TEST_CASE(select_from_table) auto database = SQL::Database::construct(db_name); create_table(database); auto result = execute(database, "INSERT INTO TestSchema.TestTable ( TextColumn, IntColumn ) VALUES ( 'Test_1', 42 ), ( 'Test_2', 43 );"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 2); result = execute(database, "INSERT INTO TestSchema.TestTable ( TextColumn, IntColumn ) VALUES ( 'Test_3', 44 ), ( 'Test_4', 45 );"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 2); result = execute(database, "INSERT INTO TestSchema.TestTable ( TextColumn, IntColumn ) VALUES ( 'Test_5', 46 );"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->inserted() == 1); result = execute(database, "SELECT * FROM TestSchema.TestTable;"); + EXPECT(result->error().code == SQL::SQLErrorCode::NoError); EXPECT(result->has_results()); EXPECT_EQ(result->results().size(), 5u); } -- cgit v1.2.3