Skip to content

#2013 migrate IterableNotToContainEntriesExpectationsSpec - #2043

Open
anushagh wants to merge 4 commits into
robstoll:mainfrom
anushagh:2013-migrate-IterableNotToContainEntriesExpectationsSpec
Open

#2013 migrate IterableNotToContainEntriesExpectationsSpec#2043
anushagh wants to merge 4 commits into
robstoll:mainfrom
anushagh:2013-migrate-IterableNotToContainEntriesExpectationsSpec

Conversation

@anushagh

Copy link
Copy Markdown

Migrate IterableNotToContainEntriesExpectationsSpec to kotlin-test

Closes #2013


I confirm that I have read the Contributor Agreements v1.0, agree to be bound on them and confirm that my contribution is compliant.

@anushagh
anushagh requested a review from robstoll as a code owner July 22, 2025 10:41
@anushagh
anushagh force-pushed the 2013-migrate-IterableNotToContainEntriesExpectationsSpec branch from f8c1ac9 to 295409c Compare July 23, 2025 10:04
@anushagh
anushagh requested a review from robstoll July 25, 2025 09:23
@anushagh
anushagh force-pushed the 2013-migrate-IterableNotToContainEntriesExpectationsSpec branch from b30f26a to f69b4ad Compare July 25, 2025 10:40
@anushagh
anushagh requested a review from robstoll July 28, 2025 09:29
Comment on lines +71 to +98
@TestFactory
fun expectationCreatorTest() = expectationCreatorTestFactory(

notToContainEntriesSpec.forExpectationCreatorTest(
"$toBeGreaterThanDescr: 8.0",
"$toBeGreaterThanDescr: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg().let { (first, rest) ->
ExpectationCreatorTestData(
oneToSeven().toList().asIterable(),
first as ExpectationCreatorTriple<Iterable<Double>>,
*(rest as Array<ExpectationCreatorTriple<Iterable<Double>>>)
)
},

notToContainNullableEntriesSpec.forExpectationCreatorTest(
"$toBeGreaterThanDescr: 8.0",
"$toBeGreaterThanDescr: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg().let { (first, rest) ->
ExpectationCreatorTestData(
oneToSeven().toList().asIterable(),
first as ExpectationCreatorTriple<Iterable<Double?>>,
*(rest as Array<ExpectationCreatorTriple<Iterable<Double?>>>),
groupPrefix = "[nullable Element] "
)
},
)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see before that you use casts here, something is odd, this shouldn't be necessary. I took a closer look, seems like kotlin apiVersion 1.4 has problems inferring the types correctly for toVarArg(). You can use the following, which doesn't use casts but requires additional type hints for the compiler

Suggested change
@TestFactory
fun expectationCreatorTest() = expectationCreatorTestFactory(
notToContainEntriesSpec.forExpectationCreatorTest(
"$toBeGreaterThanDescr: 8.0",
"$toBeGreaterThanDescr: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg().let { (first, rest) ->
ExpectationCreatorTestData(
oneToSeven().toList().asIterable(),
first as ExpectationCreatorTriple<Iterable<Double>>,
*(rest as Array<ExpectationCreatorTriple<Iterable<Double>>>)
)
},
notToContainNullableEntriesSpec.forExpectationCreatorTest(
"$toBeGreaterThanDescr: 8.0",
"$toBeGreaterThanDescr: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg().let { (first, rest) ->
ExpectationCreatorTestData(
oneToSeven().toList().asIterable(),
first as ExpectationCreatorTriple<Iterable<Double?>>,
*(rest as Array<ExpectationCreatorTriple<Iterable<Double?>>>),
groupPrefix = "[nullable Element] "
)
},
)
@TestFactory
fun expectationCreatorTest(): Any {
//TODO 2.0.0 try to inline again in case we require kotlin 1.6 at least
val doubleCase: Pair<ExpectationCreatorTriple<Iterable<Double>>, Array<out ExpectationCreatorTriple<Iterable<Double>>>> =
notToContainEntriesSpec.forExpectationCreatorTest(
"${toBeGreaterThanDescr}: 8.0",
"${toBeGreaterThanDescr}: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg()
val nullableDoubleCase: Pair<ExpectationCreatorTriple<Iterable<Double?>>, Array<out ExpectationCreatorTriple<Iterable<Double?>>>> =
notToContainNullableEntriesSpec.forExpectationCreatorTest(
"${toBeGreaterThanDescr}: 8.0",
"${toBeGreaterThanDescr}: 10.0",
{ toBeGreaterThan(8.0) }, arrayOf(expectLambda { toBeGreaterThan(10.0) })
).toVararg()
return expectationCreatorTestFactory(
ExpectationCreatorTestData(oneToSeven().toList().asIterable(), doubleCase.first, *doubleCase.second),
ExpectationCreatorTestData(
oneToSeven().toList().asIterable(),
nullableDoubleCase.first,
*nullableDoubleCase.second,
groupPrefix = "[nullable Element] "
)
)
}

expect(oneToSeven()).notToContainFun({ toEqual(3.3) }, { toEqual(1.1) }, { toEqual(2.2) })
}
}
expect(oneToSeven()).notToContainFun({ toBeGreaterThan(1.0); toBeLessThan(2.0) })

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't spot before but you need to remove this one (is the first case in testFactory):

Suggested change
expect(oneToSeven()).notToContainFun({ toBeGreaterThan(1.0); toBeLessThan(2.0) })

Comment on lines +9 to +14
class IterableNotToContainEntriesExpectationsTest :
AbstractIterableNotToContainEntriesExpectationsTest(
functionDescription to Companion::notToContainFun,
(functionDescription to Companion::notToContainNullableFun).withNullableSuffix(),
Expect<List<Int>>::notToHaveElementsOrNone.name,
) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can you put it on the same line please

Suggested change
class IterableNotToContainEntriesExpectationsTest :
AbstractIterableNotToContainEntriesExpectationsTest(
functionDescription to Companion::notToContainFun,
(functionDescription to Companion::notToContainNullableFun).withNullableSuffix(),
Expect<List<Int>>::notToHaveElementsOrNone.name,
) {
class IterableNotToContainEntriesExpectationsTest : AbstractIterableNotToContainEntriesExpectationsTest(
functionDescription to Companion::notToContainFun,
(functionDescription to Companion::notToContainNullableFun).withNullableSuffix(),
Expect<List<Int>>::notToHaveElementsOrNone.name,
) {

Comment on lines +221 to +222
fun iterable__null() {
testFactory(notToContainNullableEntriesSpec) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise no tests are executed

Suggested change
fun iterable__null() {
testFactory(notToContainNullableEntriesSpec) {
fun iterable__null() = testFactory(notToContainNullableEntriesSpec) {

@robstoll

Copy link
Copy Markdown
Owner

@anushagh I see that there are non-trivial errors in JS in the build output regarding regex which don't work as they should in JS (https://github.com/robstoll/atrium/actions/runs/16565351061/job/46847806475?pr=2043#step:5:697). I can take over from here as those errors are probably not good first issue like. Let me know what you prefer, you can also try to tackle them yourself

a: Expect<Double>.() -> Unit,
vararg aX: Expect<Double>.() -> Unit,
) = notToContainFunArr(a, aX)
testFactory(notToContainEntriesSpec) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I took a closer look, that won't work as it should, nonNullableCases is already a testFactory behind the scene, you cannot nest them. I suggest you remove the it(..) in the following lines and just keep expect(...) for now

@anushagh

Copy link
Copy Markdown
Author

@anushagh I see that there are non-trivial errors in JS in the build output regarding regex which don't work as they should in JS (https://github.com/robstoll/atrium/actions/runs/16565351061/job/46847806475?pr=2043#step:5:697). I can take over from here as those errors are probably not good first issue like. Let me know what you prefer, you can also try to tackle them yourself

Sure, I'm not sure how to fix those errors at the moment, and I'm afraid it might take me a while to do so. I'll fix the other comments though

@robstoll

Copy link
Copy Markdown
Owner

@anushagh the fixes for JS were made in main, you can rebase your branch in case you intend to continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate IterableNotToContainEntriesExpectationsSpec to kotlin-test

2 participants