Skip to content

Testing bloaters with binding

Yuval Simon edited this page Jul 1, 2017 · 3 revisions

Some bloaters must use binding information to do their job right. For instance when we have the code foo(fee());, knowing that the return type of the method fee() is some type Type, it can be bloated into Type temp = fee(); foo(temp);. But in order to do this we must have the binding information of fee() in order to know it's return type in order to bloat correctly.

Writing tests which can use binding information uses enhanced mechanism of the testing system that doesn't use binding information. Here are instructions how to use this enhanced testing system:

  1. The tests class have to extend BloaterTest such that T is the node type the bloater works on.
  2. Override the method bloater(), which have to return the tested bloater, and override the method tipsOn(), which have to return the class the bloater works on (T.class).
  3. Write a class that extends MetaFixture, which contains a compiling code that the tests would work on.
  4. Use _SuppressWarningsSpartan_ so that the class from (3) won't be spartanized.
  5. In order to test with binding use the method bloatingOf(MetaFixture) with an instance of the class from (3) as argument, and use givesWithbinding(String,String) on the result, such that the first argument is of the method to be tested (including declaration) and the second argument is the name of the method. This way, the tested bloater will be used on the original code while using binding information, and the results will be compared with the given expected results.
  • In order to write tests which check that the code is not changed (when is the wanted behaviour) need to use other class since BloaterTest still doesn't support this. In order to test this way, need to import OperandBloating and use bloatingOf method of this class the same way as for BloaterTest and then use staysWithBinding(String) (which receives the name of the method to check) on the result object.

Usage example: (Taken from test class Issue1001. The full test class can be found there)

public class Issue1001 extends BloaterTest<Assignment> {
  @Override public Tipper<Assignment> bloater() {
    return new AssignmentOperatorBloater();
  }
  @Override public Class<Assignment> tipsOn() {
    return Assignment.class;
  }
  @Test public void basic() {
    bloatingOf(Issue1001Aux.instance()).givesWithBinding("" //
        + "void f1() {\n" //
        + "  int a = 0;\n" //
        + "  a = a + 1;\n" //
        + "  x(a);" //
        + "}", "f1");
  }
  @Test public void nonMatchingPrimitives() {
    bloatingOf(Issue1001Aux.instance()).staysWithBinding();
  }
  /** [[SuppressWarningsSpartan]] */
  public static class Issue1001Aux extends MetaFixture {
    public static Issue1001Aux instance() {
      return new Issue1001Aux();
    }
    void f1() {
      int a = 0;
      a += 1;
      x(a);
    }
    void x(final int y) {}
  }
}
Clone this wiki locally