Merge "Fix failed tests on Windows" into androidx-main am: 8d8df0a47a

Original change: https://android-review.googlesource.com/c/platform/frameworks/support/+/2152754

Change-Id: I739091516b8dbe29b3609415b514d512c9acd201
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/Source.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/Source.kt
index b800570..c62cfab 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/Source.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/Source.kt
@@ -61,7 +61,7 @@
         }
 
         override val relativePath
-            get() = qName.replace(".", "/") + ".java"
+            get() = qName.replace(".", File.separator) + ".java"
     }
 
     class KotlinSource(
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
index f83b60c..39a87cd 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/compiler/SourceSet.kt
@@ -68,7 +68,7 @@
         if (!file.path.startsWith(root.path)) {
             return null
         }
-        val relativePath = path.substringAfter(root.canonicalPath + "/")
+        val relativePath = path.substringAfter(root.canonicalPath + File.separator)
         return sources.firstOrNull {
             it.relativePath == relativePath
         }
@@ -98,7 +98,7 @@
             "java" -> Source.loadJavaSource(
                 file = file,
                 qName = file.relativeTo(root).path
-                    .replace('/', '.')
+                    .replace(File.separatorChar, '.')
                     .substringBeforeLast('.') // drop .java
             )
             "kt" -> Source.loadKotlinSource(
diff --git a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/DiagnosticMessageCollectorTest.kt b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/DiagnosticMessageCollectorTest.kt
index e62ba38..ed8c35c 100644
--- a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/DiagnosticMessageCollectorTest.kt
+++ b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/DiagnosticMessageCollectorTest.kt
@@ -187,6 +187,19 @@
                     location = null
                 )
             ),
+            // ksp kotlin on Windows
+            TestParams(
+                message = "[ksp] C:\\foo\\bar\\Subject.kt:3: the real message",
+                severity = CompilerMessageSeverity.ERROR,
+                expected = RawDiagnosticMessage(
+                    kind = Diagnostic.Kind.ERROR,
+                    message = "the real message",
+                    location = Location(
+                        path = "C:\\foo\\bar\\Subject.kt",
+                        line = 3
+                    )
+                )
+            ),
         )
     }
 }
\ No newline at end of file
diff --git a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/GeneratedCodeMatchTest.kt b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/GeneratedCodeMatchTest.kt
index 08b0e61..5cebcec 100644
--- a/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/GeneratedCodeMatchTest.kt
+++ b/room/room-compiler-processing-testing/src/test/java/androidx/room/compiler/processing/util/GeneratedCodeMatchTest.kt
@@ -24,6 +24,7 @@
 import com.squareup.kotlinpoet.BOOLEAN
 import com.squareup.kotlinpoet.FileSpec
 import com.squareup.kotlinpoet.TypeSpec as KTypeSpec
+import java.io.File
 import org.junit.Test
 import org.junit.AssumptionViolatedException
 import org.junit.runner.RunWith
@@ -73,7 +74,7 @@
         }
         assertThat(result.exceptionOrNull())
             .hasMessageThat()
-            .contains("Didn't generate SourceFile[foo/bar/Baz.java]")
+            .contains("Didn't generate SourceFile[${combine("foo", "bar", "Baz.java")}]")
     }
 
     @Test
@@ -132,7 +133,7 @@
             }
             invocation.assertCompilationResult {
                 generatedSource(
-                    Source.kotlin("foo/bar/Baz.kt", file.toString())
+                    Source.kotlin(combine("foo", "bar", "Baz.kt"), file.toString())
                 )
             }
         }
@@ -165,7 +166,7 @@
                 }
                 invocation.assertCompilationResult {
                     generatedSource(
-                        Source.kotlin("foo/bar/Baz.kt", expected.toString())
+                        Source.kotlin(combine("foo", "bar", "Baz.kt"), expected.toString())
                     )
                 }
             }
@@ -216,3 +217,6 @@
             )
     }
 }
+
+private fun combine(vararg elements: String): String =
+    elements.joinToString(separator = File.separator)