From 4095be45056bf3428a384a13b65bcb7d455ed080 Mon Sep 17 00:00:00 2001 From: Lorenz Boguhn Date: Tue, 16 Dec 2025 17:25:40 +0100 Subject: [PATCH 1/4] Fix manual evaluation of files by hidding functions from output --- jsonnetunit/matcher.libsonnet | 6 +++--- jsonnetunit/std_matchers.libsonnet | 14 +++++++------- jsonnetunit/test.libsonnet | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/jsonnetunit/matcher.libsonnet b/jsonnetunit/matcher.libsonnet index a31edb3..117cfe0 100644 --- a/jsonnetunit/matcher.libsonnet +++ b/jsonnetunit/matcher.libsonnet @@ -1,7 +1,7 @@ { - satisfied: error 'must implement satisfied in concrete matcher', - positiveMessage: error 'must implement positiveMessage in concrete matcher', - negativeMessage: error 'must implement negativeMessage in concreteMatcher', + satisfied:: error 'must implement satisfied in concrete matcher', + positiveMessage:: error 'must implement positiveMessage in concrete matcher', + negativeMessage:: error 'must implement negativeMessage in concreteMatcher', matches(expectationType):: self.satisfied == expectationType, message(expectationType):: diff --git a/jsonnetunit/std_matchers.libsonnet b/jsonnetunit/std_matchers.libsonnet index 59d1057..e90b5c7 100644 --- a/jsonnetunit/std_matchers.libsonnet +++ b/jsonnetunit/std_matchers.libsonnet @@ -51,31 +51,31 @@ local thatMatcher(actual, expectation) = baseMatcher { { expect: { - matcher: equalMatcher, + matcher:: equalMatcher, expectationType: true, }, expectNot: { - matcher: equalMatcher, + matcher:: equalMatcher, expectationType: false, }, expectLt: { - matcher: ltMatcher, + matcher:: ltMatcher, expectationType: true, }, expectLe: { - matcher: leMatcher, + matcher:: leMatcher, expectationType: true, }, expectGt: { - matcher: gtMatcher, + matcher:: gtMatcher, expectationType: true, }, expectGe: { - matcher: geMatcher, + matcher:: geMatcher, expectationType: true, }, expectThat: { - matcher: thatMatcher, + matcher:: thatMatcher, expectationType: true, }, } diff --git a/jsonnetunit/test.libsonnet b/jsonnetunit/test.libsonnet index 1448321..d4b0766 100644 --- a/jsonnetunit/test.libsonnet +++ b/jsonnetunit/test.libsonnet @@ -48,5 +48,5 @@ local suite(tests) = { }; { - suite: suite, + suite:: suite, } From 69fa79d1eeaf945ed2aaf2b3bdd15eb6935ed1ec Mon Sep 17 00:00:00 2001 From: Lorenz Boguhn Date: Tue, 16 Dec 2025 18:09:35 +0100 Subject: [PATCH 2/4] Add switching to interpretable output and a result file instead of error in failure case --- jsonnetunit/test.libsonnet | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/jsonnetunit/test.libsonnet b/jsonnetunit/test.libsonnet index d4b0766..18d2c8b 100644 --- a/jsonnetunit/test.libsonnet +++ b/jsonnetunit/test.libsonnet @@ -34,14 +34,21 @@ local suite(tests) = { if !tc.matcher.matches(tc.expectationType) ]; if std.length(failures) > 0 then - local message = 'Failed %d/%d test cases:\n' % [ - std.length(failures), - std.length(self.result), - ] + std.join('\n', [ - '%s: %s' % [tc.name, tc.matcher.message(tc.expectationType)] - for tc in failures - ]); - error message + ( + local message = 'Failed %d/%d test cases' % [ + std.length(failures), + std.length(self.result), + ]; + local failureMessages = + [ + { [tc.name]: tc.matcher.message(tc.expectationType) } + for tc in failures + ]; + { + failures: failureMessages, + result: message, + } + ) else 'Passed %d test cases' % std.length(self.result) ), From 417205c5648153779b1267f5c7f12bf2ac330387 Mon Sep 17 00:00:00 2001 From: Lorenz Boguhn Date: Tue, 16 Dec 2025 18:11:12 +0100 Subject: [PATCH 3/4] Adjust std_matchers messages to be json format --- jsonnetunit/std_matchers.libsonnet | 39 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/jsonnetunit/std_matchers.libsonnet b/jsonnetunit/std_matchers.libsonnet index e90b5c7..56e4969 100644 --- a/jsonnetunit/std_matchers.libsonnet +++ b/jsonnetunit/std_matchers.libsonnet @@ -2,41 +2,60 @@ local baseMatcher = import 'matcher.libsonnet'; local equalMatcher(actual, expectation) = baseMatcher { satisfied: actual == expectation, - positiveMessage: 'Expected ' + actual + ' to be ' + expectation, - negativeMessage: 'Expected ' + actual + ' not to be ' + expectation, + positiveMessage: { + Expected: actual, + 'to be': expectation, + }, + negativeMessage: { + expected: actual, + 'not to be': expectation, + }, }; local ltMatcher(actual, expectation) = baseMatcher { satisfied: actual < expectation, - positiveMessage: 'Expected ' + actual + ' to be less than ' + expectation, + positiveMessage: { + Expected: actual, + 'to be less than': expectation, + }, }; local leMatcher(actual, expectation) = baseMatcher { satisfied: actual <= expectation, - positiveMessage: 'Expected ' + actual + - ' to be less than or equal to ' + expectation, + positiveMessage: { + Expected: actual, + 'to be less than or equal to': expectation, + }, }; local gtMatcher(actual, expectation) = baseMatcher { satisfied: actual > expectation, - positiveMessage: 'Expected ' + actual + - ' to be greater than ' + expectation, + positiveMessage: { + Expected: actual, + 'to be greater than': expectation, + }, }; local geMatcher(actual, expectation) = baseMatcher { satisfied: actual >= expectation, - positiveMessage: 'Expected ' + actual + - ' to be greater than or equal to ' + expectation, + positiveMessage: { + Expected: actual, + 'to be greater than or equal to': expectation, + }, }; local thatMatcher(actual, expectation) = baseMatcher { + local this = self, satisfied: ( if std.type(expectation) == 'function' then expectation(actual) else (expectation { actual: actual }).result ), - positiveMessage: 'Expected ' + actual + ' to satisfy ' + self.description, + positiveMessage: { + Expected: actual, + 'to satisfy': this.description, + }, description:: ( if std.type(expectation) == 'function' then 'the function' From 64918de37c3a65231361c1f574e49bb749d3732b Mon Sep 17 00:00:00 2001 From: Lorenz Boguhn Date: Tue, 16 Dec 2025 18:11:44 +0100 Subject: [PATCH 4/4] Reformat failure test objects to multiple lines --- jsonnetunit/test/failure_test.jsonnet | 11 ++++++++--- jsonnetunit/test/std_matchers_failure_test.jsonnet | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jsonnetunit/test/failure_test.jsonnet b/jsonnetunit/test/failure_test.jsonnet index 23889de..bf66a99 100644 --- a/jsonnetunit/test/failure_test.jsonnet +++ b/jsonnetunit/test/failure_test.jsonnet @@ -1,5 +1,10 @@ local test = import 'jsonnetunit/test.libsonnet'; -test.suite({ - testFailure: { actual: 1 + 1, expect: 3 }, -}) +test.suite( + { + testFailure: { + actual: 1 + 1, + expect: 3, + }, + } +) diff --git a/jsonnetunit/test/std_matchers_failure_test.jsonnet b/jsonnetunit/test/std_matchers_failure_test.jsonnet index 357cd89..ad8fd8e 100644 --- a/jsonnetunit/test/std_matchers_failure_test.jsonnet +++ b/jsonnetunit/test/std_matchers_failure_test.jsonnet @@ -1,7 +1,10 @@ local test = import 'jsonnetunit/test.libsonnet'; test.suite({ - testEq: { actual: 1, expect: 2 }, + testEq: { + actual: 1, + expect: 2, + }, testNe: { actual: 1, expectNot: 1 }, testLt: { actual: 2, expectLt: 1 },