calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/2] calcite git commit: [CALCITE-1264] Litmus argument interpolation (Chris Baynes)
Date Tue, 31 May 2016 17:28:50 GMT
Repository: calcite
Updated Branches:
  refs/heads/master f3caf13b9 -> d757201f1


[CALCITE-1264] Litmus argument interpolation (Chris Baynes)

Close apache/calcite#241


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/2f937c1b
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/2f937c1b
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/2f937c1b

Branch: refs/heads/master
Commit: 2f937c1ba354726a340968a51224131a71017979
Parents: f3caf13
Author: Chris Baynes <binaryexp+github@gmail.com>
Authored: Mon May 30 18:15:42 2016 +0200
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon May 30 23:15:43 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/calcite/util/Litmus.java    |  5 +++-
 .../java/org/apache/calcite/util/UtilTest.java  | 26 ++++++++++++++++++++
 .../calcite/adapter/druid/DruidQuery.java       |  4 +--
 3 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/2f937c1b/core/src/main/java/org/apache/calcite/util/Litmus.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Litmus.java b/core/src/main/java/org/apache/calcite/util/Litmus.java
index 0f0be55..dbdd0e3 100644
--- a/core/src/main/java/org/apache/calcite/util/Litmus.java
+++ b/core/src/main/java/org/apache/calcite/util/Litmus.java
@@ -16,6 +16,8 @@
  */
 package org.apache.calcite.util;
 
+import org.slf4j.helpers.MessageFormatter;
+
 /**
  * Callback to be called when a test for validity succeeds or fails.
  */
@@ -24,7 +26,8 @@ public interface Litmus {
    * an {@link java.lang.AssertionError} on failure. */
   Litmus THROW = new Litmus() {
     public boolean fail(String message, Object... args) {
-      final String s = message == null ? null : String.format(message, args);
+      final String s = message == null
+          ? null : MessageFormatter.arrayFormat(message, args).getMessage();
       throw new AssertionError(s);
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/2f937c1b/core/src/test/java/org/apache/calcite/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index 9afa6b6..e9af460 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -1791,6 +1791,32 @@ public class UtilTest {
     }
     assertThat(local2.get(), is("x"));
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1264">[CALCITE-1264]
+   * Litmus argument interpolation</a>. */
+  @Test public void testLitmus() {
+    boolean b = checkLitmus(2, Litmus.THROW);
+    assertThat(b, is(true));
+    b = checkLitmus(2, Litmus.IGNORE);
+    assertThat(b, is(true));
+    try {
+      b = checkLitmus(-1, Litmus.THROW);
+      fail("expected fail, got " + b);
+    } catch (AssertionError e) {
+      assertThat(e.getMessage(), is("-1 is less than 0"));
+    }
+    b = checkLitmus(-1, Litmus.IGNORE);
+    assertThat(b, is(false));
+  }
+
+  private boolean checkLitmus(int i, Litmus litmus) {
+    if (i < 0) {
+      return litmus.fail("{} is less than {}", i, 0);
+    } else {
+      return litmus.succeed();
+    }
+  }
 }
 
 // End UtilTest.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/2f937c1b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
index ee86dd3..bc51e88 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
@@ -127,7 +127,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel
{
     }
     final String signature = signature();
     if (!isValidSignature(signature)) {
-      return litmus.fail("invalid signature [%s]", signature);
+      return litmus.fail("invalid signature [{}]", signature);
     }
     if (rels.isEmpty()) {
       return litmus.fail("must have at least one rel");
@@ -161,7 +161,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel
{
         if (r instanceof Filter) {
           final Filter filter = (Filter) r;
           if (!isValidFilter(filter.getCondition())) {
-            return litmus.fail("invalid filter [%s]", filter.getCondition());
+            return litmus.fail("invalid filter [{}]", filter.getCondition());
           }
         }
       }


Mime
View raw message