summaryrefslogtreecommitdiff
path: root/src/test/test-format-table.c
Commit message (Collapse)AuthorAgeFilesLines
* test: add a test case for table_dup_cell()Frantisek Sumsal2023-04-151-0/+43
| | | | Also, sneak in coverage for "less popular" cell types.
* format-table: add field type TABLE_PATH_BASENAMELennart Poettering2022-12-231-0/+18
| | | | | | | This is just like TABLE_PATH, but only shows the basename in regular tabular output. This is useful in systemd-repart for example
* format-table: add an explicit "vertical" modeLennart Poettering2022-11-101-0/+31
| | | | | | | | | | | | | | | | | | | | | | Originally, the table formatting code was written to display a number of records, one per line, and within each line multiple fields of the same record. The first line contains the column names. It was then started to be used in a "vertical" mode however, i.e. with field names on the left instead of the top. Let's support such a mode explicitly, so that we can provide systematic styling, and can properly convert this mode to JSON. A new constructor "table_new_vertical()" is added creating such "vertical" tables. Internally, this is a table with two columns: "key" and "value". When outputting this as JSON we'll output a single JSON object, with key/value as fields. (Which is different from the traditional output where we'd use the first line as JSON field names, and output an array of objects). A new cell type TABLE_FIELD is added for specifically marking the "field" cells, i.e. the cells in the first column. We'll automatically suffic ":" to these fields on output.
* test: extend format-table tests with negative numbersFrantisek Sumsal2022-03-131-39/+44
|
* test: allow to set NULL to intro or outroYu Watanabe2022-02-021-1/+1
| | | | Addresses https://github.com/systemd/systemd/pull/22338#discussion_r796741033.
* tests: rework test macros to not take code as parametersLennart Poettering2022-02-021-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | C macros are nasty. We use them, but we try to be conservative with them. In particular passing literal, complex code blocks as argument is icky, because of "," handling of C, and also because it's quite a challange for most code highlighters and similar. Hence, let's avoid that. Using macros for genreating functions is OK but if so, the parameters should be simple words, not full code blocks. hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead of code block as argument. As side-effect this also fixes a bunch of cases where we might end up returning a negative value from main(). Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the main() functions, these are replaced by static variables, and their destructors by the static destructor logic. This doesn't fix any bugs or so, it's just supposed to make the code easier to work with and improve it easthetically. Or in other words: let's use macros where it really makes sense, but let's not go overboard with it. (And yes, FOREACH_DIRENT() is another one of those macros that take code, and I dislike that too and regret I ever added that.)
* test: Use TEST macro in more casesJan Janssen2021-11-251-27/+15
| | | | | | | | | | | | | | | This converts to TEST macro in less trivial cases. This is mostly due to having an intro or outro before/after the actual tests. Some notable changes: - add a "test" to make sure the hashmap and ordered_hashmap tests from different compilation units are actually run in test-hashmap.c - make root arg a global var in test-install-root.c - slightly rework an EFI specific test in test-proc-cmdline.c - usage of saved_argv/saved_argc in test-process-util.c - splitting test-rlimit-util.c into several tests - moving the hwdb open check into intro in test-sd-hwdb.c - condense several "tests" into one in test-udev-util.c
* json: add new JSON_BUILD_CONST_STRING() macroLennart Poettering2021-11-251-1/+1
| | | | | | | | | | | | | | | | This macro is like JSON_BUILD_STRING() but uses our json library's ability to use literal strings directly as JsonVariant objects. The changes all our codebase to use this new macro whenever we build JSON objects from literal strings. (I tried to make this automatic, i.e. to detect in JSON_BUILD_STRING() whether something is a literal string nicely and thus do this stuff automatically, but I couldn't find a way.) This should reduce memory usage of our JSON code a bit. Constant strings we use very often will now be shared and mapped directly from the ELF image.
* format-table: allow to explicitly override JSON field namesLennart Poettering2021-09-031-0/+36
| | | | | | | | | | | | In some cases it's useful to explicitly generate the JSON field names to generate for table columns, instead of auto-mangling them from table header names that are intended for human consumption. This adds the infra and a test for it. It's intended to be used by #20544, for the first column, which in text mode should have an empty header field, but have an explicit name in json output mode.
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-051-9/+9
|
* table: drop trailing white spaces of the last cell in rowYu Watanabe2021-02-191-20/+20
| | | | Fixes #18415.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* format-table: add TABLE_STRV_WRAPPEDZbigniew Jędrzejewski-Szmek2020-10-221-1/+111
| | | | | | | | | | | | | | | | | | | | | | | | | | | The idea is that we have strvs like list of server names or addresses, where the majority of strings is rather short, but some are long and there can potentially be many strings. So formattting them either all on one line or all in separate lines leads to output that is either hard to read or uses way too many rows. We want to wrap them, but relying on the pager to do the wrapping is not nice. Normal text has a lot of redundancy, so when the pager wraps a line in the middle of a word the read can understand what is going on without any trouble. But for a high-density zero-redundancy text like an IP address it is much nicer to wrap between words. This also makes c&p easier. This adds a variant of TABLE_STRV which is wrapped on output (with line breaks inserted between different strv entries). The change table_print() is quite ugly. A second pass is added to re-calculate column widths. Since column size is now "soft", i.e. it can adjust based on available columns, we need to two passes: - first we figure out how much space we want - in the second pass we figure out what the actual wrapped columns widths will be. To avoid unnessary work, the second pass is only done when we actually have wrappable fields. A test is added in test-format-table.
* test-format-table: add tests for TABLE_STRVYu Watanabe2020-01-151-0/+114
|
* format-table: natively support multiline cellsLennart Poettering2020-01-131-0/+113
| | | | This adds native support for multiline cells.
* shared/format-table: disable ellipsization when pipedZbigniew Jędrzejewski-Szmek2019-11-051-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #13461. Before: $ systemd-inhibit --no-pager WHO UID USER PID COMM WHAT WHY MODE ModemManager 0 root 1093 ModemManager sleep ModemManage… delay NetworkManager 0 root 1400 NetworkManager sleep NetworkMana… delay UPower 0 root 5141 upowerd sleep Pause devic… delay zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch External mo… block zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:… GNOME handl… block zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOME handl… delay zbyszek 1000 zbyszek 10036 gsd-power sleep GNOME needs… delay 7 inhibitors listed. $ systemd-inhibit --no-pager|grep suspend $ systemd-inhibit --no-pager|cat WHO UID USER PID COMM WHAT WHY MODE ModemManager 0 root 1093 ModemManager sleep Mode… delay NetworkManager 0 root 1400 NetworkManager sleep Netw… delay UPower 0 root 5141 upowerd sleep Paus… delay zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch Exte… block zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:h… GNOM… block zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOM… delay zbyszek 1000 zbyszek 10036 gsd-power sleep GNOM… delay After: $ build/systemd-inhibit --no-pager (same as above) $ build/systemd-inhibit --no-pager|grep suspend zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:handle-hibernate-key GNOME handling keypresses block $ build/systemd-inhibit --no-pager|cat WHO UID USER PID COMM WHAT WHY MODE ModemManager 0 root 1093 ModemManager sleep ModemManager needs to reset devices delay NetworkManager 0 root 1400 NetworkManager sleep NetworkManager needs to turn off networks delay UPower 0 root 5141 upowerd sleep Pause device polling delay zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch External monitor attached or configuration changed recently block zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:handle-hibernate-key GNOME handling keypresses block zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOME handling keypresses delay zbyszek 1000 zbyszek 10036 gsd-power sleep GNOME needs to lock the screen delay 7 inhibitors listed. Note that this affect all tools that use format-table.c: machinectl, busctl, loginctl, systemd-analyze, networkctl, portablectl.
* format-table: add some minimal testing for new table_add_many() featuresLennart Poettering2019-07-161-5/+6
|
* test: make sure colors don't confuse our testLennart Poettering2019-07-161-0/+1
|
* tree-wide: specify all table headers in lower-caseLennart Poettering2018-12-031-2/+2
|
* test: add a reproducer of issue #9549Yu Watanabe2018-07-151-0/+26
|
* basic: add minimalistic table formatterLennart Poettering2018-04-181-0/+139
We have plenty of code in our codebase that outputs tables to the console, and all is homegrown and awful. Let's replace it with a generic implementation that can do automatically what the old implementations did manually. Features: 1. Ellipsation (for fields overly long) and alignment (for fields overly short) 2. Sorting of rows 3. automatically copies formatting from the same cell in the row above 4. Heavy use of varargs to make putting together tables easy 5. can expand and compress tables, with weights 6. Has a minimal understanding of unicode wide characters in order to match unicode strings to character cell terminals. 7. Columns can be reordered and individually turned off. 8. pretty printing for various data types And more.