mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Unable to create test for non-empty constraint on listing #154
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jsundin on GitHub (Apr 28, 2024).
The intention here is to create a test for checking a non-empty constraint on a listing, for regression purposes. I realize that
pkl testhas not been documented, so it's quite possible there are some misunderstandings or unsupported functionality being used here.We need three files for a demonstration.
We can clearly see that
valuesdefined inNonEmptyImplis invalid, as the listing is required to not be empty. However, when running this test:The error seems to suggest that there is no evaluation error here. If that's the case, we should be able to try the inverse test, as demonstrated in NonEmptyTest-Inv.pkl:
This time we get the opposite error instead; an error was thrown and we did not catch it:
If we instead embed this list inside a mapping, this works as expected:
The above has been tested using the following versions:
Pkl 0.25.3 (Linux 5.15.0-1053-aws, native)Pkl 0.26.0-dev+3a31188 (Linux 5.4.0-177-generic, native)@odenix commented on GitHub (Apr 28, 2024):
I think everything works as expected here. (
NonEmptyTest-Inv.pklisn’t the inverse test.) This should work:Here is a more robust test that doesn’t depend on the exact error message:
@holzensp commented on GitHub (Apr 29, 2024):
This is because there isn't. Where you say
confUnderTest, you just refer to the object; nothing's forcing the evaluation of its members. If, instead, you sayconfUnderTest.output.textorconfUnderTest.values.length, you force the evaluation ofvaluesand it throws as you'd expect (sotest.catchcatches it and the test passes).Actually; that's not as expected. This is a known bug.
Mapping<K,V>is too eager; it should be strict in its keys and lazy in its values, but currently, type checking it forces its values. (See: https://github.com/apple/pkl/issues/406)