[Enhancment] Calling `expectSelfie()` from another package
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the cross-package ErrorSpec example and inspect SelfieImplementations/DiskSelfie.toMatchDisk(), especially the behavior around line 38 and CallLocation source lookup. Compare it with toMatchDisk_TODO(). Done means the public API can validate and write snapshots from another package without relying on TODO behavior or overwriting them on every run.
Written by the indexing model from the issue text.
Description
Hello, the library is pretty useful, but I'm stumbling into a problem that I'm not sure how to fix.
Using Kotest, I want to create a reusable Spec to snapshot tests my custom exceptions and their localization.
It ends up looking kind of like this:
package mypackage.errors
abstract class ErrorSpec<T : Error>(
private val clazz: KClass<T>,
private val create: () -> T
) :
FunSpec({
context("Localisation") {
forAll(Exhaustive.collection(SUPPORTED_LOCALES)) {
expectSelfie(json.encodeToString(clazz.serializer(), create())).toMatchDisk()
}
}
})
class ErrorTest : ErrorSpec<Error>(
clazz = Error::class,
create = { Error() }
)
This work perfectly, until I put ErrorSpec in another package.
The main reason I want to do this is to use a testFixtures.
This then ends up failing at runtime with:
org.opentest4j.AssertionFailedError:
Couldn't find source file for CallLocation(
clazz=mypackage.ErrorSpec$1$1,
method=invokeSuspend,
fileName=Specs.kt,
line=36
),
looked in TypedPath(absolutePath=[...]/mypackage/src/test/kotlin/)
and [[...]/mypackage/src/test/resources],
maybe there are other source roots?
What I don't understand is that, if I use toMatchDisk_TODO() instead of toMatchDisk(), the snapshot files end up being written, but the tests fails on writeLine.
Manually changing the value of isTodo to true in SelfieImplementations/DiskSelfie.toMatchDisk():38, the tests pass successfully, with the snapshot file being written at the correct place (albeit being overwritten every run, which kind of defeat the point).
Is there a way to do what I want using the public API?
If not, would it be possible to implement?
- Dominant language
- Kotlin
- Stars
- 101
- Forks
- 18
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diffplug/selfie
-
Selfie JVM Snapshot Garbage Collection is overly zealous when using multiple test suites in gradle Openbug jvm
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
enhancement jvm
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
bug jvm
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
bug docs jvm
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
-
bug jvm py
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Telegram !!! Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Xposed-Modules-Repo/com.fuck.iab#24 · 3 comments · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SimonHalvdansson/Harmonic-HN#361 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
johanhaleby/occurrent#1120 ·