New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read/write table data to a file #3197
Conversation
Readme-oriented programming to make sure the proposed API make sense
documentation/versioned_docs/version-5.4/assertions/table_driven_testing.md
Show resolved
Hide resolved
documentation/versioned_docs/version-5.4/assertions/table_driven_testing.md
Outdated
Show resolved
Hide resolved
documentation/versioned_docs/version-5.4/assertions/table_driven_testing.md
Outdated
Show resolved
Hide resolved
documentation/versioned_docs/version-5.4/assertions/table_driven_testing.md
Show resolved
Hide resolved
documentation/versioned_docs/version-5.4/assertions/table_driven_testing.md
Show resolved
Hide resolved
All rows must have the right number of columns
@Kantis probably need some refactoring and handle variants with 20 generic types, but I think I cover the main use cases now. ouch was lots of work :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! 🤘 Added various suggestions. Would like a third pair of eyes on this once it's ready 👀
...rtions/kotest-assertions-core/src/jvmTest/kotlin/com/sksamuel/kotest/data/StringTableTest.kt
Show resolved
Hide resolved
...rtions/kotest-assertions-core/src/jvmTest/kotlin/com/sksamuel/kotest/data/StringTableTest.kt
Show resolved
Hide resolved
...rtions/kotest-assertions-core/src/jvmTest/kotlin/com/sksamuel/kotest/data/StringTableTest.kt
Outdated
Show resolved
Hide resolved
kotest-assertions/kotest-assertions-shared/src/commonMain/kotlin/io/kotest/data/StringTable.kt
Outdated
Show resolved
Hide resolved
if (exists().not()) throw AssertionError("Can't read table file") | ||
if (extension != "table") throw AssertionError("Table file must have a .table extension") | ||
val lines = readLines() | ||
if (lines.isEmpty()) throw AssertionError("Table file must have a header") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to throw IllegalArgumentException
s instead? No assertion has been made at this point, I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can decide. Personally I don't like exceptions since they don't work well with assertSoftly
for example.
test("invalid file") {
val file = resourcesDir.resolve("invalid.table")
val table = table(headers, file, transform) // implicit assertion that the file exists
table shouldBe expectedTable
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a difference between an assertion (E.g. validating the output of production code) and a bug in test code. IMO this AssertionError
would indicate a fault in the test code, not the main code and I think the distinction is clearer when output as an exception. What do you think?
It's ready-ish now. Also
|
@Kantis I'm happy if you are. |
There's a chance we'll try to get #3264 out tonight, so disabled auto-merge for now. |
Thanks @jmfayard 💯 |
amazing, thanks! |
This is a very cool feature, why isn't it documented? I stumbled upon it randomly while digging through the source code. |
Thank you! I found out about it because I was trying to come up with something similar, either using Markdown tables or with a DSL (I did a nice hack but it doesn't work if the first value is a number, due to standard lib operators). But is the page released? Still can't find it in the docs... maybe the index needs to be updated as well? |
Mhh yes, it seems to be missing from these sidebar files:
|
Resolves #3179
See the discussion in the README
I'm starting with readme-oriented programming, documenting how the end result should look like to make sure it makes sense.
Update 1st september needs refactoring but most features are there I think.
Documentation needs updates:
file.writeTable(headers, rows)
and only works forRowN<String, String, ..., String>
table.mapRows { }
if you are usingRowN
with types other thanString
map.toTable()
is a quick way to produce a table from a maptable(headers, list.map { row(...) })
is a quick way to produce a table from a list