Adam S
02/11/2023, 9:10 AM`
└── site/
├── styles/
│ └── site.css
├── images/
│ └── icon.png
└── index.html
the expected/actual so the test assertion is just a simple string-comparison check, and I like that it would give a clear test-failure
How can I generate such a pretty tree in Kotlin/JVM? Or maybe there’s a test assertion library that can help?import java.io.File
fun File.toPrettyTreeString(): String {
return walk().joinToString("\n") { file ->
val relativeFile = file.relativeTo(this)
val depth = relativeFile.invariantSeparatorsPath.count { it == '/' }
file.name.prependIndent(" ".repeat(depth))
}
}
generates:
html
index.html
-basic -project
it.protected
index.html
-protected-class
index.html
protected-fun.html
-protected-class.html
Next step is to try and compare file contents….Damien O'Hara
02/11/2023, 3:25 PMdrawFileTree
code if it helps: https://github.com/mfwgenerics/markout/blob/7a1b81e3a6c773b67fa42e3977599b3285a5e930/readme/src/main/kotlin/Util.kt#L58-L104`
└── site
├── styles
│ └── site.css
├── images
│ └── icon.png
└── index.html
hope it helps!Adam S
02/11/2023, 8:36 PMDamien O'Hara
02/12/2023, 3:19 AMjava.nio.file.Path
(obtainable by calling File.toPath
)Adam S
02/12/2023, 9:26 AMval entries = dir.listDirectoryEntries()
to
val entries = dir.toFile().walk().maxDepth(1).toList()
since Gradle 7.6 limits Kotlin to 1.4val entries = dir.toFile().walk().maxDepth(1).filter { it != dir.toFile() }
Damien O'Hara
02/12/2023, 10:31 AM