Re: [PATCH v6 02/10] test-lib-functions: improve diagnostic output for trace2 data assertions
René Scharfe <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <[email protected]> |
On 7/11/26 3:27 PM, Kristofer Karlsson via GitGitGadget wrote:
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 809c662124..3521efe5d7 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1996,6 +1996,42 @@ test_trace2_data () {
> grep -e '"category":"'"$1"'","key":"'"$2"'","value":"'"$3"'"'
> }
>
> +# Check that the given trace2 data event has the expected value and
> +# appears exactly once. Produces a diagnostic on failure.
> +#
> +# test_trace2_data_singular <category> <key> <value> [<label>]
> +test_trace2_data_singular () {
> + local category="$1" key="$2" expect_val="$3"
> + local label_suffix="${4:+ [$4]}"
> + local kv_pattern='"category":"'"$category"'","key":"'"$key"'","value":"\([^"]*\)"'
> + local actual
> +
> + actual=$(sed -n "s|.*${kv_pattern}.*|\1|p") &&
> +
> + if test -z "$actual"
> + then
> + echo >&4 "error: trace2 data '$category/$key'$label_suffix not found"
> + return 1
> + fi &&
> +
> + case "$actual" in
> + *"
> +"*)
Nit: You could use $LF here instead of this two-line string.
René