From 5bbb874565f3b52dfbe2afd5daf349299c4d6f97 Mon Sep 17 00:00:00 2001 From: Wojciech Potiopa Date: Sat, 22 Jun 2019 09:28:02 +0200 Subject: [PATCH] Unit tests for target annotations selection, workaround for ceylon bug https://github.com/eclipse/ceylon/issues/7448 (#6) --- .../herd/depin/engine/DefaultResolver.ceylon | 10 +++++++-- ...AnnotationsFromConstructorParameter.ceylon | 21 +++++++++++++++++++ .../herd/depin/engine/ceylon/package.ceylon | 1 + .../integration/ClassInjectionTest.ceylon | 10 +++++++-- .../targetedConstructorDependencies.ceylon | 7 +++++++ .../TargetWithTwoCallableConstructors.ceylon | 17 +++++++++++++++ .../engine/integration/model/fixture.ceylon | 4 ++++ 7 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 test/test/herd/depin/engine/ceylon/AnnotationsFromConstructorParameter.ceylon create mode 100644 test/test/herd/depin/engine/ceylon/package.ceylon create mode 100644 test/test/herd/depin/engine/integration/dependencies/targetedConstructorDependencies.ceylon create mode 100644 test/test/herd/depin/engine/integration/model/TargetWithTwoCallableConstructors.ceylon diff --git a/source/herd/depin/engine/DefaultResolver.ceylon b/source/herd/depin/engine/DefaultResolver.ceylon index 432dbe2..3771bbe 100644 --- a/source/herd/depin/engine/DefaultResolver.ceylon +++ b/source/herd/depin/engine/DefaultResolver.ceylon @@ -17,9 +17,15 @@ import ceylon.language.meta { shared class DefaultResolver(Registry registry) satisfies Resolver{ shared actual Dependency resolve(Declaration declaration) { if(is TypedDeclaration&AnnotatedDeclaration declaration){ - - value annotations = declaration.annotations() + variable {Annotation*} annotations; + try{ + annotations = declaration.annotations() .select((Annotation element) => registry.controls.contains(type(element))); + }catch(Exception x){ + //Ceylon BUG!!! We can't identifiy parameter by annotations but for now we can use name of the parameter. + //This will be enough for most of cases. + annotations={NamedAnnotation(declaration.name)}; + } return Dependency{ type = declaration.openType; identification = if (annotations.empty && registry.controls.contains(`NamedAnnotation`)) diff --git a/test/test/herd/depin/engine/ceylon/AnnotationsFromConstructorParameter.ceylon b/test/test/herd/depin/engine/ceylon/AnnotationsFromConstructorParameter.ceylon new file mode 100644 index 0000000..3b646fa --- /dev/null +++ b/test/test/herd/depin/engine/ceylon/AnnotationsFromConstructorParameter.ceylon @@ -0,0 +1,21 @@ +import ceylon.test { + test, + ignore +} +shared class ConstructorTestClass{ + String param; + shared new (String param){ + this.param = param;} +} + +shared class AnnotationsFromConstructorParameter() { + + ignore + shared test void shouldGetAnnotationsFromConstructorParameter(){ + assert (exists constructor = `class ConstructorTestClass`.defaultConstructor); + assert(exists param=constructor.parameterDeclarations.first); + assert(param.annotations().empty); + } + + +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/ceylon/package.ceylon b/test/test/herd/depin/engine/ceylon/package.ceylon new file mode 100644 index 0000000..c659845 --- /dev/null +++ b/test/test/herd/depin/engine/ceylon/package.ceylon @@ -0,0 +1 @@ +shared package test.herd.depin.engine.ceylon; diff --git a/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon index 522b48d..9f398b6 100644 --- a/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon +++ b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon @@ -1,5 +1,6 @@ import ceylon.test { - test + test, + ignore } import herd.depin.engine { @@ -12,7 +13,8 @@ import test.herd.depin.engine.integration.model { DataSource, DefaultParametersConstructor, DefaultedParametersByFunction, - DefaultedParameterFunction + DefaultedParameterFunction, + TargetWithTwoCallableConstructors } shared class ClassInjectionTest() { @@ -36,4 +38,8 @@ shared class ClassInjectionTest() { shared test void shouldInjectDefaultedParameterClassFunction(){ assert(depin.inject(`DefaultedParameterFunction`).fun()==fixture.defaultedParameterFunction.param); } + ignore("until https://github.com/eclipse/ceylon/issues/7448 fixed") + shared test void shouldInjectTargetedConstructor(){ + assert(depin.inject(`TargetWithTwoCallableConstructors`).something==fixture.targetWithTwoCallableConstructors.param.reversed); + } } \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/dependencies/targetedConstructorDependencies.ceylon b/test/test/herd/depin/engine/integration/dependencies/targetedConstructorDependencies.ceylon new file mode 100644 index 0000000..5f1a042 --- /dev/null +++ b/test/test/herd/depin/engine/integration/dependencies/targetedConstructorDependencies.ceylon @@ -0,0 +1,7 @@ +import test.herd.depin.engine.integration.model { + fixture +} +import herd.depin.engine { + dependency +} +shared dependency String something =fixture.targetWithTwoCallableConstructors.param; \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/TargetWithTwoCallableConstructors.ceylon b/test/test/herd/depin/engine/integration/model/TargetWithTwoCallableConstructors.ceylon new file mode 100644 index 0000000..653d5ac --- /dev/null +++ b/test/test/herd/depin/engine/integration/model/TargetWithTwoCallableConstructors.ceylon @@ -0,0 +1,17 @@ +import herd.depin.engine { + target, + named +} +shared class TargetWithTwoCallableConstructors { + + shared String something; + shared new (String something){ + this.something = something; + + } + + shared target new targetedConstructor(named("Abc") String something){ + this.something=something.reversed; + } + +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/fixture.ceylon b/test/test/herd/depin/engine/integration/model/fixture.ceylon index 82b990e..cd1fbf1 100644 --- a/test/test/herd/depin/engine/integration/model/fixture.ceylon +++ b/test/test/herd/depin/engine/integration/model/fixture.ceylon @@ -23,4 +23,8 @@ shared object fixture { shared object defaultedParameterFunction { shared String param = "abc"; } + shared object targetWithTwoCallableConstructors{ + shared String param ="abc"; + shared TargetWithTwoCallableConstructors instance= TargetWithTwoCallableConstructors(param); + } } \ No newline at end of file