mirror of https://github.com/sbt/sbt.git
Use IO.withTemporaryDirectory instead of File.createTempFile
This commit is contained in:
parent
05cd00e135
commit
e877187e3c
|
|
@ -19,10 +19,7 @@ import verify.BasicTestSuite
|
|||
object JUnitXmlTestsListenerSpec extends BasicTestSuite:
|
||||
|
||||
test("JUnitXmlTestsListener should log debug message when writing test report"):
|
||||
val tempDir = File.createTempFile("junit-test", "")
|
||||
tempDir.delete()
|
||||
tempDir.mkdirs()
|
||||
try
|
||||
IO.withTemporaryDirectory: tempDir =>
|
||||
val loggedMessages = new AtomicReference[List[String]](Nil)
|
||||
val mockLogger = new AbstractLogger:
|
||||
def getLevel: Level.Value = Level.Debug
|
||||
|
|
@ -66,17 +63,9 @@ object JUnitXmlTestsListenerSpec extends BasicTestSuite:
|
|||
messages.exists(_.contains("TEST-TestSuite.xml")),
|
||||
s"Expected log message containing 'TEST-TestSuite.xml', but got: $messages"
|
||||
)
|
||||
finally
|
||||
// Cleanup
|
||||
if tempDir.exists() then
|
||||
tempDir.listFiles().foreach(_.delete())
|
||||
tempDir.delete()
|
||||
|
||||
test("JUnitXmlTestsListener should handle null logger gracefully"):
|
||||
val tempDir = File.createTempFile("junit-test", "")
|
||||
tempDir.delete()
|
||||
tempDir.mkdirs()
|
||||
try
|
||||
IO.withTemporaryDirectory: tempDir =>
|
||||
val listener = new JUnitXmlTestsListener(tempDir, false, null)
|
||||
listener.doInit()
|
||||
listener.startGroup("TestSuite")
|
||||
|
|
@ -97,9 +86,5 @@ object JUnitXmlTestsListenerSpec extends BasicTestSuite:
|
|||
// Verify XML file was still created
|
||||
val xmlFile = new File(tempDir, "TEST-TestSuite.xml")
|
||||
assert(xmlFile.exists(), "XML file should be created even when logger is null")
|
||||
finally
|
||||
if tempDir.exists() then
|
||||
tempDir.listFiles().foreach(_.delete())
|
||||
tempDir.delete()
|
||||
|
||||
end JUnitXmlTestsListenerSpec
|
||||
|
|
|
|||
Loading…
Reference in New Issue