diff --git a/plugins/org.jnario/src/org/jnario/typing/JnarioTypeComputer.java b/plugins/org.jnario/src/org/jnario/typing/JnarioTypeComputer.java index 9861c0642..ebf482889 100644 --- a/plugins/org.jnario/src/org/jnario/typing/JnarioTypeComputer.java +++ b/plugins/org.jnario/src/org/jnario/typing/JnarioTypeComputer.java @@ -69,9 +69,8 @@ protected void _computeTypes(final XAbstractFeatureCall featureCall, } } } - } else { - super._computeTypes(featureCall, state); } + super._computeTypes(featureCall, state); } private boolean canHandleNullArg(JvmOperation operation) { diff --git a/tests/org.jnario.tests/doc-gen/org/jnario/JnarioSuite.html b/tests/org.jnario.tests/doc-gen/org/jnario/JnarioSuite.html index 3c2abcee6..cc517efb6 100644 --- a/tests/org.jnario.tests/doc-gen/org/jnario/JnarioSuite.html +++ b/tests/org.jnario.tests/doc-gen/org/jnario/JnarioSuite.html @@ -127,6 +127,7 @@

Jnario

  • ExampleNameProvider
  • Implicit Subject
  • Introducing Jnario Specs
  • +
  • Linker validation
  • Mocking ~
  • OperationNameProvider
  • Pending
  • diff --git a/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.html b/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.html new file mode 100644 index 000000000..1ce9df0c2 --- /dev/null +++ b/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.html @@ -0,0 +1,280 @@ + + + + +Linker validation + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +
    +
    +
    +
    • No validation errors

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      1 should not be 2
      +    }
      +  }
      +'''.parse.validate.assertNoIssues
      +
    • Unknown variable

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      println(abc)
      +    }
      +  }
      +'''.parse.validate.assertIssues(
      +  "The method or field abc is undefined"
      +)
      +
    • Unknown variable within should_be_0

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      abc should be 0
      +    }
      +  }
      +'''.parse.validate.assertIssues(
      +  "The method or field abc is undefined"
      +)
      +
    • Unknown variable within should_be_null [Bug -137]

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      abc should be null
      +    }
      +  }
      +'''.parse.validate.assertIssues(
      +  "The method or field abc is undefined"
      +)
      +
    • Unknown variable within => null

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      abc => null
      +    }
      +  }
      +'''.parse.validate.assertIssues(
      +  "The method or field abc is undefined"
      +)
      +
    • Method call with should be null

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      string => null
      +    }
      +    def getString() {""}
      +  }
      +'''.parse.validate.assertNoIssues
      +
    • Null variable with should be null

      +
      +'''
      +  package bootstrap
      +
      +  describe "something"{
      +    fact "x" {
      +      val withoutType = null
      +      withoutType => null
      +    }
      +  }
      +'''.parse.validate.assertNoIssues
      +
    +
    +
    +

    SpecLinkerValidation.spec

    +

    +

    +package org.jnario.spec.tests.unit.validation
    +
    +import com.google.inject.Inject
    +import java.util.List
    +import org.eclipse.emf.ecore.EObject
    +import org.eclipse.xtext.junit4.util.ParseHelper
    +import org.eclipse.xtext.junit4.validation.ValidationTestHelper
    +import org.eclipse.xtext.validation.Issue
    +import org.jnario.jnario.test.util.SpecTestCreator
    +import org.jnario.runner.CreateWith
    +import org.junit.Assert
    +
    +@CreateWith(typeof(SpecTestCreator))
    +describe "Linker validation"{
    +  @Inject extension ParseHelper< EObject > parseHelper
    +  @Inject extension ValidationTestHelper validationTestHelper
    +
    +  fact "No validation errors"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          1 should not be 2
    +        }
    +      }
    +    '''.parse.validate.assertNoIssues
    +  }
    +
    +  fact "Unknown variable"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          println(abc)
    +        }
    +      }
    +    '''.parse.validate.assertIssues(
    +      "The method or field abc is undefined"
    +    )
    +  }
    +
    +  fact "Unknown variable within should_be_0"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          abc should be 0
    +        }
    +      }
    +    '''.parse.validate.assertIssues(
    +      "The method or field abc is undefined"
    +    )
    +  }
    +
    +  fact "Unknown variable within should_be_null (Bug #137)"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          abc should be null
    +        }
    +      }
    +    '''.parse.validate.assertIssues(
    +      "The method or field abc is undefined"
    +    )
    +  }
    +
    +  fact "Unknown variable within => null"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          abc => null
    +        }
    +      }
    +    '''.parse.validate.assertIssues(
    +      "The method or field abc is undefined"
    +    )
    +  }
    +
    +  fact "Method call with should be null"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          string => null
    +        }
    +        def getString() {""}
    +      }
    +    '''.parse.validate.assertNoIssues
    +  }
    +
    +  fact "Null variable with should be null"{
    +    '''
    +      package bootstrap
    +
    +      describe "something"{
    +        fact "x" {
    +          val withoutType = null
    +          withoutType => null
    +        }
    +      }
    +    '''.parse.validate.assertNoIssues
    +  }
    +
    +  def assertNoIssues(List<Issue> issues) {
    +    issues.size => 0
    +  }
    +
    +  def assertIssues(List<Issue> issues, String ... parts) {
    +    val sb = new StringBuilder
    +  for (issue : issues.filter[!parts.exists[part| message.contains(part)]]) {
    +    sb.append("- unmatched actual issue: ")
    +    sb.append(issue)
    +    sb.append(System.getProperty("line.separator"))
    +  }
    +  for (part : parts.filter[part | !issues.exists[message.contains(part)]]) {
    +    sb.append("- unmatched expected issue part: ")
    +    sb.append(part)
    +    sb.append(System.getProperty("line.separator"))
    +  }
    +  if (sb.length > 0) {
    +    Assert.fail('''
    +      Issue mismatch
    +      «sb.toString»
    +    ''');
    +  }
    +  }
    +
    +}
    +
    +

    +
    +
    +
    +
    +
    + +
    + + + diff --git a/tests/org.jnario.tests/src/org/jnario/spec/tests/unit/validation/SpecLinkerValidation.spec b/tests/org.jnario.tests/src/org/jnario/spec/tests/unit/validation/SpecLinkerValidation.spec new file mode 100644 index 000000000..9b99edbbd --- /dev/null +++ b/tests/org.jnario.tests/src/org/jnario/spec/tests/unit/validation/SpecLinkerValidation.spec @@ -0,0 +1,136 @@ +package org.jnario.spec.tests.unit.validation + +import com.google.inject.Inject +import java.util.List +import org.eclipse.emf.ecore.EObject +import org.eclipse.xtext.junit4.util.ParseHelper +import org.eclipse.xtext.junit4.validation.ValidationTestHelper +import org.eclipse.xtext.validation.Issue +import org.jnario.jnario.test.util.SpecTestCreator +import org.jnario.runner.CreateWith +import org.junit.Assert + +@CreateWith(typeof(SpecTestCreator)) +describe "Linker validation"{ + @Inject extension ParseHelper< EObject > parseHelper + @Inject extension ValidationTestHelper validationTestHelper + + fact "No validation errors"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + 1 should not be 2 + } + } + '''.parse.validate.assertNoIssues + } + + fact "Unknown variable"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + println(abc) + } + } + '''.parse.validate.assertIssues( + "The method or field abc is undefined" + ) + } + + fact "Unknown variable within should_be_0"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + abc should be 0 + } + } + '''.parse.validate.assertIssues( + "The method or field abc is undefined" + ) + } + + fact "Unknown variable within should_be_null (Bug #137)"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + abc should be null + } + } + '''.parse.validate.assertIssues( + "The method or field abc is undefined" + ) + } + + fact "Unknown variable within => null"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + abc => null + } + } + '''.parse.validate.assertIssues( + "The method or field abc is undefined" + ) + } + + fact "Method call with should be null"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + string => null + } + def getString() {""} + } + '''.parse.validate.assertNoIssues + } + + fact "Null variable with should be null"{ + ''' + package bootstrap + + describe "something"{ + fact "x" { + val withoutType = null + withoutType => null + } + } + '''.parse.validate.assertNoIssues + } + + def assertNoIssues(List issues) { + issues.size => 0 + } + + def assertIssues(List issues, String ... parts) { + val sb = new StringBuilder + for (issue : issues.filter[!parts.exists[part| message.contains(part)]]) { + sb.append("- unmatched actual issue: ") + sb.append(issue) + sb.append(System.getProperty("line.separator")) + } + for (part : parts.filter[part | !issues.exists[message.contains(part)]]) { + sb.append("- unmatched expected issue part: ") + sb.append(part) + sb.append(System.getProperty("line.separator")) + } + if (sb.length > 0) { + Assert.fail(''' + Issue mismatch + «sb.toString» + '''); + } + } + +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/SpecSuite.java b/tests/org.jnario.tests/xtend-gen/org/jnario/SpecSuite.java index 0bb1814a0..cd0037c7c 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/SpecSuite.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/SpecSuite.java @@ -30,11 +30,12 @@ import org.jnario.spec.tests.unit.naming.SpecQualifiedNameProviderSpec; import org.jnario.spec.tests.unit.scoping.SpecScopeProviderSpec; import org.jnario.spec.tests.unit.spec.SpecExecutableProviderSpec; +import org.jnario.spec.tests.unit.validation.LinkerValidationSpec; import org.jnario.spec.tests.unit.validation.SpecJavaValidatorSpec; import org.junit.runner.RunWith; @Named("Spec") -@Contains({ AnnotationsSpec.class, AssertionSpec.class, CompilerSpec.class, CustomizingTheSpecCreationSpec.class, DefiningSpecBaseClassesSpec.class, DefiningXtendClassesInYourSpecsSpec.class, ExampleSpec.class, ExampleGroupSpec.class, ExampleNameProviderSpec.class, ImplicitSubjectSpec.class, IntroducingJnarioSpecsSpec.class, MockingSpec.class, OperationNameProviderSpec.class, PendingSpec.class, SetupTeardownSpec.class, SpecExtensionsSpec.class, SpecDocGeneratorSpec.class, SpecExecutableProviderSpec.class, SpecJavaValidatorSpec.class, SpecQualifiedNameProviderSpec.class, SpecsSpec.class, SpecScopeProviderSpec.class, StaticImportsSpec.class, ThrowsSpec.class, UsingJUnitRulesInSpecsSpec.class, UsingShouldSpec.class, UsingTablesSpec.class, UsingXtendSWithOperatorSpec.class }) +@Contains({ AnnotationsSpec.class, AssertionSpec.class, CompilerSpec.class, CustomizingTheSpecCreationSpec.class, DefiningSpecBaseClassesSpec.class, DefiningXtendClassesInYourSpecsSpec.class, ExampleSpec.class, ExampleGroupSpec.class, ExampleNameProviderSpec.class, ImplicitSubjectSpec.class, IntroducingJnarioSpecsSpec.class, LinkerValidationSpec.class, MockingSpec.class, OperationNameProviderSpec.class, PendingSpec.class, SetupTeardownSpec.class, SpecExtensionsSpec.class, SpecDocGeneratorSpec.class, SpecExecutableProviderSpec.class, SpecJavaValidatorSpec.class, SpecQualifiedNameProviderSpec.class, SpecsSpec.class, SpecScopeProviderSpec.class, StaticImportsSpec.class, ThrowsSpec.class, UsingJUnitRulesInSpecsSpec.class, UsingShouldSpec.class, UsingTablesSpec.class, UsingXtendSWithOperatorSpec.class }) @RunWith(ExampleGroupRunner.class) @SuppressWarnings("all") public class SpecSuite { diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.java new file mode 100644 index 000000000..8595a153e --- /dev/null +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/spec/tests/unit/validation/LinkerValidationSpec.java @@ -0,0 +1,296 @@ +package org.jnario.spec.tests.unit.validation; + +import com.google.inject.Inject; +import java.util.List; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.junit4.util.ParseHelper; +import org.eclipse.xtext.junit4.validation.ValidationTestHelper; +import org.eclipse.xtext.validation.Issue; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.jnario.test.util.SpecTestCreator; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.CreateWith; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@CreateWith(SpecTestCreator.class) +@Named("Linker validation") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class LinkerValidationSpec { + @Inject + @Extension + @org.jnario.runner.Extension + public ParseHelper parseHelper; + + @Inject + @Extension + @org.jnario.runner.Extension + public ValidationTestHelper validationTestHelper; + + @Test + @Named("No validation errors") + @Order(1) + public void _noValidationErrors() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("1 should not be 2"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertNoIssues(_validate); + } + + @Test + @Named("Unknown variable") + @Order(2) + public void _unknownVariable() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("println(abc)"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertIssues(_validate, + "The method or field abc is undefined"); + } + + @Test + @Named("Unknown variable within should_be_0") + @Order(3) + public void _unknownVariableWithinShouldBe0() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("abc should be 0"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertIssues(_validate, + "The method or field abc is undefined"); + } + + @Test + @Named("Unknown variable within should_be_null [Bug -137]") + @Order(4) + public void _unknownVariableWithinShouldBeNullBug137() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("abc should be null"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertIssues(_validate, + "The method or field abc is undefined"); + } + + @Test + @Named("Unknown variable within => null") + @Order(5) + public void _unknownVariableWithinNull() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("abc => null"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertIssues(_validate, + "The method or field abc is undefined"); + } + + @Test + @Named("Method call with should be null") + @Order(6) + public void _methodCallWithShouldBeNull() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("string => null"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append(" "); + _builder.append("def getString() {\"\"}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertNoIssues(_validate); + } + + @Test + @Named("Null variable with should be null") + @Order(7) + public void _nullVariableWithShouldBeNull() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe \"something\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"x\" {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("val withoutType = null"); + _builder.newLine(); + _builder.append(" "); + _builder.append("withoutType => null"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + EObject _parse = this.parseHelper.parse(_builder); + List _validate = this.validationTestHelper.validate(_parse); + this.assertNoIssues(_validate); + } + + public boolean assertNoIssues(final List issues) { + int _size = issues.size(); + Assert.assertTrue("\nExpected issues.size => 0 but" + + "\n issues.size is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_size)).toString() + + "\n issues is " + new org.hamcrest.StringDescription().appendValue(issues).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(_size), Integer.valueOf(0))); + + return Should.operator_doubleArrow(Integer.valueOf(_size), Integer.valueOf(0)); + } + + public void assertIssues(final List issues, final String... parts) { + final StringBuilder sb = new StringBuilder(); + final Function1 _function = new Function1() { + public Boolean apply(final Issue it) { + final Function1 _function = new Function1() { + public Boolean apply(final String part) { + String _message = it.getMessage(); + return Boolean.valueOf(_message.contains(part)); + } + }; + boolean _exists = IterableExtensions.exists(((Iterable)Conversions.doWrapArray(parts)), _function); + return Boolean.valueOf((!_exists)); + } + }; + Iterable _filter = IterableExtensions.filter(issues, _function); + for (final Issue issue : _filter) { + { + sb.append("- unmatched actual issue: "); + sb.append(issue); + String _property = System.getProperty("line.separator"); + sb.append(_property); + } + } + final Function1 _function_1 = new Function1() { + public Boolean apply(final String part) { + final Function1 _function = new Function1() { + public Boolean apply(final Issue it) { + String _message = it.getMessage(); + return Boolean.valueOf(_message.contains(part)); + } + }; + boolean _exists = IterableExtensions.exists(issues, _function); + return Boolean.valueOf((!_exists)); + } + }; + Iterable _filter_1 = IterableExtensions.filter(((Iterable)Conversions.doWrapArray(parts)), _function_1); + for (final String part : _filter_1) { + { + sb.append("- unmatched expected issue part: "); + sb.append(part); + String _property = System.getProperty("line.separator"); + sb.append(_property); + } + } + int _length = sb.length(); + boolean _greaterThan = (_length > 0); + if (_greaterThan) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("Issue mismatch"); + _builder.newLine(); + String _string = sb.toString(); + _builder.append(_string, ""); + _builder.newLineIfNotEmpty(); + org.junit.Assert.fail(_builder.toString()); + } + } +}