diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 3565c11..8ff6375 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -15,5 +15,8 @@ jobs: - name: OPA check strict run: opa check --strict test/ - - name: Check formatting - run: opa fmt --diff --fail test/ + - name: Setup Regal + uses: StyraInc/setup-regal@v0.2.0 + with: + version: latest + - run: regal lint --format github test/ diff --git a/.regal/config.yaml b/.regal/config.yaml new file mode 100644 index 0000000..bbc3b43 --- /dev/null +++ b/.regal/config.yaml @@ -0,0 +1,7 @@ +rules: + idiomatic: + no-defined-entrypoint: + level: ignore + testing: + print-or-trace-call: + level: ignore diff --git a/test/assert.rego b/test/assert.rego index e903f39..aa4e01f 100644 --- a/test/assert.rego +++ b/test/assert.rego @@ -6,151 +6,150 @@ package test.assert import future.keywords.every +import future.keywords.if import future.keywords.in # METADATA # description: Assert expected is equal to result -equals(expected, result) { +equals(expected, result) if { expected == result -} else := false { +} else := false if { print("expected equals:", _quote_str(expected), "got:", result) } # METADATA # description: Assert expected is not equal to result -not_equals(expected, result) { +not_equals(expected, result) if { expected != result -} else := false { +} else := false if { print("expected not equals:", _quote_str(expected), "got:", result) } # METADATA # description: Assert all items in coll are equal to value -all_equals(coll, value) { +all_equals(coll, value) if { every item in coll { item == value } -} else := false { +} else := false if { exceptions := [item | some item in coll; item != value] print("expected all items to have value", _append_comma(value), "failed for", exceptions) } # METADATA # description: Assert no items in coll are equal to value -none_equals(coll, value) { +none_equals(coll, value) if { every item in coll { item != value } -} else := false { +} else := false if { exceptions := [item | some item in coll; item == value] print("expected no items to have value", _append_comma(value), "failed for", exceptions) } # METADATA # description: Assert item is in coll -has(item, coll) { +has(item, coll) if { item in coll -} else := false { +} else := false if { print("expected", type_name(item), _quote_str(item), "in", type_name(coll), "got:", coll) } # METADATA # description: Assert item is not in coll -not_has(item, coll) { +not_has(item, coll) if { not item in coll -} else := false { +} else := false if { print("expected", type_name(item), _quote_str(item), "not in", type_name(coll), "got:", coll) } # METADATA # description: Assert provided collection is empty -empty(coll) { +empty(coll) if { count(coll) == 0 -} else := false { +} else := false if { print("expected empty", type_name(coll), "got:", coll) } # METADATA # description: Assert provided collection is not empty -not_empty(coll) { +not_empty(coll) if { count(coll) != 0 -} else := false { +} else := false if { print("expected not empty", type_name(coll)) } # METADATA # description: Assert string starts with search -starts_with(str, search) { +starts_with(str, search) if { startswith(str, search) -} else := false { +} else := false if { print("expected", _quote_str(str), "to start with", _quote_str(search)) } # METADATA # description: Assert string ends with search -ends_with(str, search) { +ends_with(str, search) if { endswith(str, search) -} else := false { +} else := false if { print("expected", _quote_str(str), "to end with", _quote_str(search)) } # METADATA # description: Assert all strings in coll starts with search -all_starts_with(coll, search) { +all_starts_with(coll, search) if { every str in coll { startswith(str, search) } -} else := false { +} else := false if { exceptions := [str | some str in coll; not startswith(str, search)] print("expected all strings to start with", _append_comma(search), "failed for", exceptions) } # METADATA # description: Assert all strings in coll ends with search -all_ends_with(coll, search) { +all_ends_with(coll, search) if { every str in coll { endswith(str, search) } -} else := false { +} else := false if { exceptions := [str | some str in coll; not endswith(str, search)] print("expected all strings to end with", _append_comma(search), "failed for", exceptions) } # METADATA # description: Assert no strings in coll starts with search -none_starts_with(coll, search) { +none_starts_with(coll, search) if { every str in coll { not startswith(str, search) } -} else := false { +} else := false if { exceptions := [str | some str in coll; startswith(str, search)] print("expected no strings to start with", _append_comma(search), "failed for", exceptions) } # METADATA # description: Assert no strings in coll ends with search -none_ends_with(coll, search) { +none_ends_with(coll, search) if { every str in coll { not endswith(str, search) } -} else := false { +} else := false if { exceptions := [str | some str in coll; endswith(str, search)] print("expected no strings to end with", _append_comma(search), "failed for", exceptions) } # METADATA # description: Fail with provided message -fail(msg) { +fail(msg) if { print(msg) + + # regal ignore:constant-condition false } -_quote_str(x) := concat("", [`"`, x, `"`]) { - is_string(x) -} +_quote_str(x) := concat("", [`"`, x, `"`]) if is_string(x) -_quote_str(x) := x { - not is_string(x) -} +_quote_str(x) := x if not is_string(x) _append_comma(str) := sprintf("%v,", [_quote_str(str)])