Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spec] Stacktraces within table forEach are incomplete #58

Open
borisbrodski opened this issue Nov 29, 2012 · 8 comments
Open

[Spec] Stacktraces within table forEach are incomplete #58

borisbrodski opened this issue Nov 29, 2012 · 8 comments

Comments

@borisbrodski
Copy link
Collaborator

If within a table forEach closure an exception get thrown, no correct stacktrace (for the first erroneous table row) get shown.

Example:

package test

describe "Stacktraces should be also correct within table forEach lambdas"{
    def table {
        | a |
        | 1 |
    }

    fact "throw exception in the table forEach" {
        table.forEach [   // <------------------------------- line 41
            throw new Exception
        ]
    }
}

Produces:

java.lang.AssertionError: table failed

        | a       |
        | <1>     | ✘     (1)

(1) java.lang.Exception
    at org.jnario.lib.ExampleTableIterators.newAssertionError(ExampleTableIterators.java:67)
    at org.jnario.lib.ExampleTableIterators.perform(ExampleTableIterators.java:62)
    at org.jnario.lib.ExampleTableIterators.forEach(ExampleTableIterators.java:34)
    at de.finkonsens.pingo.testtools.rules.test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec._throwExceptionInTheTableForEach(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jnario.runner.ExampleRunner.runChild(ExampleRunner.java:101)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:236)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:1)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

As you can see, the first interesting line in the stack trace is

at de.finkonsens.pingo.testtools.rules.test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec._throwExceptionInTheTableForEach(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:41)

But the line 41 is not the line, the exception thrown.

I would expect to see a "caused by" exception below this stack trace with the original exception thrown, so the cause of the exception could be investigated easier.

@sebastianbenz
Copy link
Owner

Hm. I can't reproduce this. With your example I get the following exception:


java.lang.AssertionError: table failed

        | a       |
        | <1>     | ✘     (1)

(1) java.lang.Exception
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec$1.apply(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:34)
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec$1.apply(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:1)
    at org.jnario.lib.ExampleTableIterators.perform(ExampleTableIterators.java:55)
    at org.jnario.lib.ExampleTableIterators.forEach(ExampleTableIterators.java:34)
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec._throwExceptionInTheTableForEach(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

and double clicking the first line brings me to the correct line in my spec. Is it possible that you original example is a little bit different?

@borisbrodski
Copy link
Collaborator Author

That's weird. I updated Jnario to 0.3.0.201211300028 and retested posted example again. I still get

java.lang.AssertionError: table failed

        | a       |
        | <1>     | ✘     (1)

(1) java.lang.Exception
    at org.jnario.lib.ExampleTableIterators.newAssertionError(ExampleTableIterators.java:67)
    at org.jnario.lib.ExampleTableIterators.perform(ExampleTableIterators.java:62)
    at org.jnario.lib.ExampleTableIterators.forEach(ExampleTableIterators.java:34)
    at de.finkonsens.pingo.testtools.xfactory.test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec._throwExceptionInTheTableForEach(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jnario.runner.ExampleRunner.runChild(ExampleRunner.java:101)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:248)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:1)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Any ideas?

Tested on Windows XP 32, Eclipse 3.8 (not 4.2).

@sebastianbenz
Copy link
Owner

Could you please post the generated Java code.

@borisbrodski
Copy link
Collaborator Author

StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:

package de.finkonsens.pingo.testtools.xfactory.test;

import de.finkonsens.pingo.testtools.xfactory.test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.jnario.lib.ExampleTable;
import org.jnario.lib.ExampleTableIterators;
import org.jnario.runner.ExampleGroupRunner;
import org.jnario.runner.Named;
import org.jnario.runner.Order;
import org.junit.Test;
import org.junit.runner.RunWith;

@SuppressWarnings("all")
@RunWith(ExampleGroupRunner.class)
@Named("Stacktraces should be also correct within table forEach lambdas")
public class StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec {
  public ExampleTable<StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable> _initStacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable() {
    return ExampleTable.create("table", 
      java.util.Arrays.asList("a"), 
      new StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable(  java.util.Arrays.asList("1"), 1)
    );
  }

  protected ExampleTable<StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable> table = _initStacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable();

  @Test
  @Named("throw exception in the table forEach")
  @Order(1)
  public void _throwExceptionInTheTableForEach() throws Exception {
    final Procedure1<StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable> _function = new Procedure1<StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable>() {
        public void apply(final StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable it) {
          try {
            Exception _exception = new Exception();
            throw _exception;
          } catch (Exception _e) {
            throw Exceptions.sneakyThrow(_e);
          }
        }
      };
    ExampleTableIterators.<StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable>forEach(this.table, _function);
  }
}

and

StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable.java:

package de.finkonsens.pingo.testtools.xfactory.test;

import java.util.List;
import org.jnario.lib.ExampleTableRow;

public class StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable extends ExampleTableRow {
  public StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpecTable(final List<String> cellNames, final int a) {
    super(cellNames);
    this.a = a;
  }

  public int a;

  public int getA() {
    return a;
  }

  public List<String> getCells() {
    return java.util.Arrays.asList(toString(a));
  }
}

@sebastianbenz
Copy link
Owner

Hm. The generated Java code is identical. This is the exception I get from your generated java classes:


java.lang.AssertionError: table failed

        | a       |
        | <1>     | ✘     (1)

(1) java.lang.Exception
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec$1.apply(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:34)
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec$1.apply(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:1)
    at org.jnario.lib.ExampleTableIterators.perform(ExampleTableIterators.java:55)
    at org.jnario.lib.ExampleTableIterators.forEach(ExampleTableIterators.java:34)
    at test.StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec._throwExceptionInTheTableForEach(StacktracesShouldBeAlsoCorrectWithinTableForEachLambdasSpec.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

Sorry - I can't reproduce your stacktrace.

@borisbrodski
Copy link
Collaborator Author

I get the correct (your) stack trace, if I test it with the eclipse 4.2 (juno). But using eclipse 3.8 (juno without e4) I still get this wrong stack trace.

@borisbrodski
Copy link
Collaborator Author

Reproduced this bug with the stand-alone Jnario Compiler:
https://github.com/borisbrodski/JnarioStacktracesWithinTableForEachProblem

Check out the project and run default ant target.

Here are some snippets:

package test

describe "Tests type inference of the table columns"{
  def myTable {
    | MyEnum value   |
    | MyEnum::VALUE1 |
    | MyEnum::VALUE2 |
  }     

  fact "Table column type get inferred by the stand-alone compile correctly" {  // <--- Line 32 in Java
    myTable.forEach [                                                           // <--- Line 35 in Java
      acceptPruefungsArt(value)
      throw new RuntimeException
    ]
  }
  def acceptPruefungsArt(MyEnum myEnum) {}
}

JUnit report:

Testsuite: test.AllTestsSuite
Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0,031 sec

Testcase: Table column type get inferred by the stand-alone compile correctly took 0,015 sec
    FAILED
myTable failed

        | value        |
        | <VALUE1>     | ✘     (1)
        | <VALUE2>     | ✘     (2)

(1) java.lang.RuntimeException
(2) java.lang.RuntimeException
junit.framework.AssertionFailedError: myTable failed

        | value        |
        | <VALUE1>     | ✘     (1)
        | <VALUE2>     | ✘     (2)

(1) java.lang.RuntimeException
(2) java.lang.RuntimeException
    at test.TestsTypeInferenceOfTheTableColumnsSpec$1.apply(TestsTypeInferenceOfTheTableColumnsSpec.java:35)
    at test.TestsTypeInferenceOfTheTableColumnsSpec$1.apply(TestsTypeInferenceOfTheTableColumnsSpec.java:32)
    at org.jnario.lib.ExampleTableIterators.perform(ExampleTableIterators.java:55)
    at org.jnario.lib.ExampleTableIterators.forEach(ExampleTableIterators.java:34)
    at test.TestsTypeInferenceOfTheTableColumnsSpec._tableColumnTypeGetInferredByTheStandAloneCompileCorrectly(TestsTypeInferenceOfTheTableColumnsSpec.java:39)
    at org.jnario.runner.ExampleRunner.runChild(ExampleRunner.java:101)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:236)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:1)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:236)
    at org.jnario.runner.ExampleGroupRunner.runChild(ExampleGroupRunner.java:1)

The line 35 doesn't point to the

throw new RuntimeException

@borisbrodski
Copy link
Collaborator Author

Same problem with Jnario 0.5.1.201307292301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants