Skip java-api-generator tests when running on windows-type OS 84/95684/4
authorOleksii Mozghovyi <oleksii.mozghovyi@pantheon.tech>
Tue, 6 Apr 2021 20:06:27 +0000 (23:06 +0300)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 9 Apr 2021 06:45:31 +0000 (08:45 +0200)
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 <oleksii.mozghovyi@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java

index 7232ff4260e68f17dbdba26853235eba41246cfc..b7babc8e7e7f448cf339563a142b0089f3a52160 100644 (file)
@@ -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);
+    }
 }
index 750780a3f93bfe714973beb8e92f084e91a3abfb..20c0ed26f55f7f09ed2a7b870d38d376ece2f698 100644 (file)
@@ -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,