@@ -947,6 +947,18 @@ def _cue_vet_test_impl(ctx):
947947
948948 concrete_flag = "'-c'" if ctx .attr .concrete else ""
949949
950+ # Choose invocation style based on should_fail (known at analysis time)
951+ if ctx .attr .should_fail :
952+ vet_invocation = """\
953+ if "${{CUE}}" vet "${{vet_args[@]+"${{vet_args[@]}}}}" {instance_arg} "${{data_files[@]}}"; then
954+ echo >&2 "cue vet succeeded but failure was expected"
955+ exit 1
956+ else
957+ exit 0
958+ fi"""
959+ else :
960+ vet_invocation = 'exec "${{CUE}}" vet "${{vet_args[@]+"${{vet_args[@]}}}}" {instance_arg} "${{data_files[@]}}"'
961+
950962 runfiles_boilerplate = """\
951963 # Copy-pasted from the Bazel Bash runfiles library v2.
952964set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
@@ -985,7 +997,7 @@ vet_args=()
985997{concrete_line}
986998{schema_expr_lines}
987999
988- exec "${{CUE}}" vet "${{vet_args[@]+"${{vet_args[@]}}}}" {instance_arg} "${{data_files[@]}}"
1000+ {vet_invocation}
9891001""" .format (
9901002 runfiles_boilerplate = runfiles_boilerplate ,
9911003 cue_tool_rlocation = _runfile_path (ctx , cue_tool ),
@@ -994,6 +1006,7 @@ exec "${{CUE}}" vet "${{vet_args[@]+"${{vet_args[@]}}}}" {instance_arg} "${{data
9941006 concrete_line = 'vet_args+=({})' .format (concrete_flag ) if concrete_flag else "# concrete flag not set" ,
9951007 schema_expr_lines = schema_expr_lines if schema_expr_lines else "# no schema expressions" ,
9961008 instance_arg = instance_arg ,
1009+ vet_invocation = vet_invocation .format (instance_arg = instance_arg ),
9971010 )
9981011
9991012 script = ctx .actions .declare_file (ctx .label .name + "_vet_test.sh" )
@@ -1043,6 +1056,10 @@ Each expression is passed as a "-d" flag to "cue vet".""",
10431056 doc = "Require all values to be concrete (passes -c to cue vet)." ,
10441057 default = True ,
10451058 ),
1059+ "should_fail" : attr .bool (
1060+ doc = "When True, the test passes if cue vet exits non-zero (i.e. validation fails as expected)." ,
1061+ default = False ,
1062+ ),
10461063 "_bash_runfiles" : attr .label (
10471064 default = Label ("@bazel_tools//tools/bash/runfiles" ),
10481065 ),
0 commit comments