Skip to content

Commit

Permalink
Enable tests to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed May 12, 2024
1 parent cd3ef2b commit d42991c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,29 @@ public void testReferenceNonexistentAlias()
}

/*
* There are so many ways for matches to fail that this is not likely to be generally useful.
* here are so many ways for matches to fail that this is not likely to be generally useful.
* Pending better diagnostics, please leave this here, and restrict its use to simple queries
* that have few ways to not match a pattern, and functionality that is well-tested with
* positive tests.
*/
private void assertFails(Runnable runnable)
private void assertPlanFails(Runnable runnable)
{
boolean failed = false;
try {
runnable.run();
fail("Plans should not have matched!");
}
catch (AssertionError e) {
//ignored
failed = true;
}
if (!failed) {
fail("Query was expected to fail but passed");
}
}

@Test
public void testStrictOutputExtraSymbols()
{
assertFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem",
assertPlanFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem",
strictOutput(ImmutableList.of("ORDERKEY"),
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey",
"EXTENDEDPRICE", "extendedprice")))));
Expand All @@ -229,15 +232,15 @@ public void testStrictOutputExtraSymbols()
@Test
public void testStrictTableScanExtraSymbols()
{
assertFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem",
assertPlanFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem",
output(ImmutableList.of("ORDERKEY", "EXTENDEDPRICE"),
strictTableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))));
}

@Test
public void testStrictProjectExtraSymbols()
{
assertFails(() -> assertMinimallyOptimizedPlan("SELECT discount, orderkey, 1 + orderkey FROM lineitem",
assertPlanFails(() -> assertMinimallyOptimizedPlan("SELECT discount, orderkey, 1 + orderkey FROM lineitem",
output(ImmutableList.of("ORDERKEY", "EXPRESSION"),
strictProject(ImmutableMap.of("EXPRESSION", expression("1 + ORDERKEY"), "ORDERKEY", expression("ORDERKEY")),
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testMetadataIsClearedAfterQueryFailed()
queryRunner.execute(sql);
fail("expected exception");
}
catch (Throwable t) {
catch (RuntimeException t) {
// query should fail
}

Expand Down

0 comments on commit d42991c

Please sign in to comment.