Commit Graph

6 Commits

Author SHA1 Message Date
David Sterba ebd046eb8d btrfs-progs: tests: renumber json test cases so they match the parameter
The test utility takes a numeric parameter from 1 to max tests but this
is off by one to the test case function names. Unify that so it's clear
which test fails.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba ede538f98d btrfs-progs: print null value for empty uuid in json
This is a potentially breaking change to json output. An all zeros uuid
was printed as "-" but we can utilize native json type null for that.
Note the va_copy must be used as va_arg advances the pointer.

{
	"nulluuid": null
}

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba 386765be15 btrfs-progs: tests: fix build warnings in json tests (-Wmissing-prototypes)
The test cases should be static, otherwise it leads to a warning like

    [LD]     json-formatter-test
tests/json-formatter-test.c:40:6: warning: no previous prototype for ‘test_simple_empty’ [-Wmissing-prototypes]
   40 | void test_simple_empty()
      |      ^~~~~~~~~~~~~~~~~

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba be5cb7dfe9 btrfs-progs: add bool type to json
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:23 +02:00
David Sterba ecbb6a7fcd btrfs-progs: add json formatter for escaped string
Add formatter type 'str' where the string must be escaped, e.g. paths or
internal data. Otherwise plain %s can be printed if it's known that
there are no special characters.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-12-16 00:40:32 +01:00
David Sterba 9bf6b5c837 btrfs-progs: tests: add json formatter test coverage
Add a simple framework to exercise the json formatter and add testing
target that validates the output.

Run 'make test-json' to execute all available tests, requires 'jq'
utility for validation (https://github.com/stedolan/jq).

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00