diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2016-11-19 18:49:46 +0000 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2016-11-19 18:49:46 +0000 |
commit | f296277d200474a34f411d289a92da86f63dad5e (patch) | |
tree | 85636cfffbf0b0b4ebd8697e4a7ce00f95f0c98d /tests/test_normalized_component.py | |
parent | ef4bc1fddc438276708917e2341b80c37a76100f (diff) | |
download | google-fruit-f296277d200474a34f411d289a92da86f63dad5e.tar.gz |
Use proper Python indentation in Python-based e2e tests.
Diffstat (limited to 'tests/test_normalized_component.py')
-rwxr-xr-x | tests/test_normalized_component.py | 239 |
1 files changed, 126 insertions, 113 deletions
diff --git a/tests/test_normalized_component.py b/tests/test_normalized_component.py index 668c008..0940044 100755 --- a/tests/test_normalized_component.py +++ b/tests/test_normalized_component.py @@ -17,168 +17,181 @@ from nose2.tools import params from fruit_test_common import * COMMON_DEFINITIONS = ''' -#include <fruit/fruit.h> -#include <vector> -#include "test_macros.h" + #include <fruit/fruit.h> + #include <vector> + #include "test_macros.h" -struct Annotation1 {}; -struct Annotation2 {}; -''' + struct Annotation1 {}; + struct Annotation2 {}; + ''' @params( ('X', 'X', 'Y'), ('fruit::Annotated<Annotation1, X>', 'ANNOTATED(Annotation1, X)', 'fruit::Annotated<Annotation2, Y>')) def test_success_normalized_component_provides_unused(XAnnot, X_ANNOT, YAnnot): - expect_success( - COMMON_DEFINITIONS + ''' -struct X {}; - -struct Y { - INJECT(Y(X_ANNOT)) {}; -}; + source = ''' + struct X {}; -fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { - return fruit::createComponent(); -} + struct Y { + INJECT(Y(X_ANNOT)) {}; + }; -fruit::Component<XAnnot> getXComponent(X& x) { - return fruit::createComponent() - .bindInstance<XAnnot, X>(x); -} + fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { + return fruit::createComponent(); + } -int main() { - fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); + fruit::Component<XAnnot> getXComponent(X& x) { + return fruit::createComponent() + .bindInstance<XAnnot, X>(x); + } - X x{}; + int main() { + fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); - fruit::Injector<XAnnot> injector(normalizedComponent, getXComponent(x)); - injector.get<XAnnot>(); -} -''', - locals()) + X x{}; + fruit::Injector<XAnnot> injector(normalizedComponent, getXComponent(x)); + injector.get<XAnnot>(); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) @params( ('X', 'X', 'Y'), ('fruit::Annotated<Annotation1, X>', 'ANNOTATED(Annotation1, X)', 'fruit::Annotated<Annotation2, Y>')) def test_success(XAnnot, X_ANNOT, YAnnot): - expect_success( - COMMON_DEFINITIONS + ''' -struct X {}; + source = ''' + struct X {}; -struct Y { - INJECT(Y(X_ANNOT)) {}; -}; + struct Y { + INJECT(Y(X_ANNOT)) {}; + }; -fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { - return fruit::createComponent(); -} + fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { + return fruit::createComponent(); + } -fruit::Component<XAnnot> getXComponent(X& x) { - return fruit::createComponent() - .bindInstance<XAnnot, X>(x); -} + fruit::Component<XAnnot> getXComponent(X& x) { + return fruit::createComponent() + .bindInstance<XAnnot, X>(x); + } -int main() { - fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); + int main() { + fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); - X x{}; + X x{}; - fruit::Injector<YAnnot> injector(normalizedComponent, getXComponent(x)); - injector.get<YAnnot>(); -} -''', - locals()) + fruit::Injector<YAnnot> injector(normalizedComponent, getXComponent(x)); + injector.get<YAnnot>(); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) @params( ('X', 'X', 'Y'), ('fruit::Annotated<Annotation1, X>', 'ANNOTATED(Annotation1, X)', 'fruit::Annotated<Annotation2, Y>')) def test_success_inline_component(XAnnot, X_ANNOT, YAnnot): - expect_success( - COMMON_DEFINITIONS + ''' -struct X {}; + source = ''' + struct X {}; -struct Y { - INJECT(Y(X_ANNOT)) {}; -}; + struct Y { + INJECT(Y(X_ANNOT)) {}; + }; -fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { - return fruit::createComponent(); -} + fruit::Component<fruit::Required<XAnnot>, YAnnot> getComponent() { + return fruit::createComponent(); + } -int main() { - fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); + int main() { + fruit::NormalizedComponent<fruit::Required<XAnnot>, YAnnot> normalizedComponent(getComponent()); - X x{}; + X x{}; - fruit::Injector<YAnnot> injector(normalizedComponent, - fruit::Component<XAnnot>(fruit::createComponent().bindInstance<XAnnot, X>(x))); - injector.get<YAnnot>(); -} -''', - locals()) + fruit::Injector<YAnnot> injector(normalizedComponent, + fruit::Component<XAnnot>(fruit::createComponent().bindInstance<XAnnot, X>(x))); + injector.get<YAnnot>(); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) @params('X', 'fruit::Annotated<Annotation1, X>') def test_unsatisfied_requirements(XAnnot): + source = ''' + struct X { + INJECT(X()); + }; + + fruit::Component<fruit::Required<XAnnot>> getComponent() { + return fruit::createComponent(); + } + + int main() { + fruit::NormalizedComponent<fruit::Required<XAnnot>> normalizedComponent(getComponent()); + fruit::Injector<> injector(normalizedComponent, fruit::Component<>(fruit::createComponent())); + } + ''' expect_compile_error( - 'UnsatisfiedRequirementsInNormalizedComponentError<XAnnot>', - 'The requirements in UnsatisfiedRequirements are required by the NormalizedComponent but are not provided by the Component', - COMMON_DEFINITIONS + ''' -struct X { - INJECT(X()); -}; - -fruit::Component<fruit::Required<XAnnot>> getComponent() { - return fruit::createComponent(); -} - -int main() { - fruit::NormalizedComponent<fruit::Required<XAnnot>> normalizedComponent(getComponent()); - fruit::Injector<> injector(normalizedComponent, fruit::Component<>(fruit::createComponent())); -} -''', - locals()) + 'UnsatisfiedRequirementsInNormalizedComponentError<XAnnot>', + 'The requirements in UnsatisfiedRequirements are required by the NormalizedComponent but are not provided by the Component', + COMMON_DEFINITIONS, + source, + locals()) @params('X', 'fruit::Annotated<Annotation1, X>') def test_error_repeated_type(XAnnot): - expect_compile_error( - 'RepeatedTypesError<XAnnot,XAnnot>', - 'A type was specified more than once.', - COMMON_DEFINITIONS + ''' -struct X {}; + source = ''' + struct X {}; -void f() { - (void) sizeof(fruit::NormalizedComponent<XAnnot, XAnnot>); -} -''', - locals()) + void f() { + (void) sizeof(fruit::NormalizedComponent<XAnnot, XAnnot>); + } + ''' + expect_compile_error( + 'RepeatedTypesError<XAnnot,XAnnot>', + 'A type was specified more than once.', + COMMON_DEFINITIONS, + source, + locals()) def test_error_repeated_type_with_different_annotation_ok(): - expect_success( - COMMON_DEFINITIONS + ''' -struct X {}; + source = ''' + struct X {}; -using XAnnot1 = fruit::Annotated<Annotation1, X>; -using XAnnot2 = fruit::Annotated<Annotation2, X>; + using XAnnot1 = fruit::Annotated<Annotation1, X>; + using XAnnot2 = fruit::Annotated<Annotation2, X>; -void f() { - (void) sizeof(fruit::NormalizedComponent<XAnnot1, XAnnot2>); -} -''') + void f() { + (void) sizeof(fruit::NormalizedComponent<XAnnot1, XAnnot2>); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source) @params('X', 'fruit::Annotated<Annotation1, X>') def test_error_type_required_and_provided(XAnnot): + source = ''' + struct X {}; + + void f() { + (void) sizeof(fruit::NormalizedComponent<fruit::Required<XAnnot>, XAnnot>); + } + ''' expect_compile_error( - 'RepeatedTypesError<XAnnot, XAnnot>', - 'A type was specified more than once.', - COMMON_DEFINITIONS + ''' -struct X {}; - -void f() { - (void) sizeof(fruit::NormalizedComponent<fruit::Required<XAnnot>, XAnnot>); -} -''', - locals()) + 'RepeatedTypesError<XAnnot, XAnnot>', + 'A type was specified more than once.', + COMMON_DEFINITIONS, + source, + locals()) if __name__ == '__main__': import nose2 |