From c7a253cf0d7514b7665553709dc42b9ae522b4e9 Mon Sep 17 00:00:00 2001 From: Oleksii Mozghovyi Date: Tue, 6 Apr 2021 23:06:27 +0300 Subject: [PATCH] Skip java-api-generator tests when running on windows-type OS Xtend code generation uses the "line.separator" system property to generate proper line endings, and there is no possibility to override this setting w/o modifying the system property. This change disables some tests to avoid misleading failures when running those on the windows type os. Change-Id: I8c9b2776d45a149debe3948ef0d2ce8a682c79d6 Signed-off-by: Oleksii Mozghovyi Signed-off-by: Robert Varga --- .../api/generator/BuilderGeneratorTest.java | 29 ++++++++++++------- .../java/api/generator/test/Bug5151Test.java | 4 +++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java index 7232ff4260..b7babc8e7e 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.spy; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.xtend2.lib.StringConcatenation; import org.junit.Test; import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingGenerator; import org.opendaylight.mdsal.binding.model.api.GeneratedType; @@ -39,7 +40,7 @@ public class BuilderGeneratorTest { public void builderTemplateGenerateHashcodeWithPropertyTest() { final GeneratedType genType = mockGenType("get" + TEST); - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#hashCode()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent" + " hashing\n" @@ -64,7 +65,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateHashCodeWithMorePropertiesTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#hashCode()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent" + " hashing\n" @@ -85,7 +86,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateHashCodeWithoutPropertyWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#hashCode()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent" + " hashing\n" @@ -105,7 +106,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateHashCodeWithPropertyWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#hashCode()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent" + " hashing\n" @@ -126,7 +127,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateHashCodeWithMorePropertiesWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#hashCode()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent" + " hashing\n" @@ -150,7 +151,7 @@ public class BuilderGeneratorTest { public void builderTemplateGenerateToStringWithPropertyTest() { final GeneratedType genType = mockGenType("get" + TEST); - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -168,7 +169,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateToStringWithoutAnyPropertyTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -185,7 +186,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateToStringWithMorePropertiesTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -204,7 +205,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateToStringWithoutPropertyWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -222,7 +223,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateToStringWithPropertyWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -241,7 +242,7 @@ public class BuilderGeneratorTest { @Test public void builderTemplateGenerateToStringWithMorePropertiesWithAugmentTest() throws Exception { - assertEquals("/**\n" + assertXtendEquals("/**\n" + " * Default implementation of {@link Object#toString()} contract for this interface.\n" + " * Implementations of this interface are encouraged to defer to this method to get consistent string" + "\n * representations across all implementations.\n" @@ -349,4 +350,10 @@ public class BuilderGeneratorTest { doReturn(ValueMechanics.NORMAL).when(methSign).getMechanics(); return methSign; } + + // Xtend's StringConcatenation is using runtime-configured line separator, which can change between runs, notably + // it has a different value on Windows. Make sure we account for that. + private static void assertXtendEquals(final String expected, final String actual) { + assertEquals(expected.replace("\n", StringConcatenation.DEFAULT_LINE_DELIMITER), actual); + } } diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java index 750780a3f9..20c0ed26f5 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java @@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.java.api.generator.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeFalse; import java.io.File; import java.util.Map; @@ -23,6 +24,9 @@ public class Bug5151Test extends BaseCompilationTest { @Test public void test() throws Exception { + // Xtend code generation uses the "line.separator" system property to generate proper line endings + // in templates, leading to test failures running on Windows-type OS. + assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID); final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID); generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID, -- 2.36.6