Write tests for dynamic versions with ivy and maven resolvers
and refactor tests #KT-27051 fixed this commit is just a confirmation of the fix: either it worked from the beginning, or was fixed by some unrelated change
This commit is contained in:
+21
-4
@@ -107,6 +107,17 @@ done
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveStdJUnitDynVer() {
|
||||
val (_, err) = captureOutAndErr {
|
||||
Assert.assertNull(compileScript("args-junit-dynver-error.kts", StandardArgsScriptTemplateWithMavenResolving::class))
|
||||
}
|
||||
Assert.assertTrue("Expecting error: unresolved reference: assertThrows", err.contains("error: unresolved reference: assertThrows"))
|
||||
|
||||
val scriptClass = compileScript("args-junit-dynver.kts", StandardArgsScriptTemplateWithMavenResolving::class)
|
||||
Assert.assertNotNull(scriptClass)
|
||||
}
|
||||
|
||||
private fun compileScript(
|
||||
scriptFileName: String,
|
||||
scriptTemplate: KClass<out Any>,
|
||||
@@ -170,18 +181,24 @@ done
|
||||
private fun String.linesSplitTrim() =
|
||||
split('\n','\r').map(String::trim).filter(String::isNotBlank)
|
||||
|
||||
private fun captureOut(body: () -> Unit): String {
|
||||
private fun captureOut(body: () -> Unit): String = captureOutAndErr(body).first
|
||||
|
||||
private fun captureOutAndErr(body: () -> Unit): Pair<String, String> {
|
||||
val outStream = ByteArrayOutputStream()
|
||||
val errStream = ByteArrayOutputStream()
|
||||
val prevOut = System.out
|
||||
val prevErr = System.err
|
||||
System.setOut(PrintStream(outStream))
|
||||
System.setErr(PrintStream(errStream))
|
||||
try {
|
||||
body()
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
System.out.flush()
|
||||
System.err.flush()
|
||||
System.setOut(prevOut)
|
||||
System.setErr(prevErr)
|
||||
}
|
||||
return outStream.toString()
|
||||
return outStream.toString() to errStream.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
|
||||
@file:DependsOn("junit:junit:(4.11,4.12]")
|
||||
|
||||
org.junit.Assert.assertThrows(NullPointerException::class.java) {
|
||||
throw null!!
|
||||
}
|
||||
|
||||
println("Hello, world!")
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
@file:DependsOn("junit:junit:(4.12,5.0)")
|
||||
|
||||
org.junit.Assert.assertThrows(NullPointerException::class.java) {
|
||||
throw null!!
|
||||
}
|
||||
|
||||
println("Hello, world!")
|
||||
|
||||
Reference in New Issue
Block a user