]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add tests for column --table-header-as-columns
authorKarel Zak <kzak@redhat.com>
Mon, 16 Feb 2026 10:22:12 +0000 (11:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Feb 2026 10:22:12 +0000 (11:22 +0100)
Add test coverage for the --table-header-as-columns (-K) option
added in PR #4003.

Tests cover:
- Basic tab-separated input with header line
- CSV input with comma separator
- JSON output with header-derived column names
- Empty column names in header

Addresses: https://github.com/util-linux/util-linux/pull/4003
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/expected/column/table-header-as-columns [new file with mode: 0644]
tests/expected/column/table-header-as-columns-csv [new file with mode: 0644]
tests/expected/column/table-header-as-columns-empty [new file with mode: 0644]
tests/expected/column/table-header-as-columns-json [new file with mode: 0644]
tests/ts/column/table

diff --git a/tests/expected/column/table-header-as-columns b/tests/expected/column/table-header-as-columns
new file mode 100644 (file)
index 0000000..17595cd
--- /dev/null
@@ -0,0 +1,3 @@
+NAME   AGE  CITY  
+Alice  30   New   York
+Bob    25   Los   Angeles
diff --git a/tests/expected/column/table-header-as-columns-csv b/tests/expected/column/table-header-as-columns-csv
new file mode 100644 (file)
index 0000000..a3b1452
--- /dev/null
@@ -0,0 +1,3 @@
+NAME   AGE  CITY
+Alice  30   New York
+Bob    25   Los Angeles
diff --git a/tests/expected/column/table-header-as-columns-empty b/tests/expected/column/table-header-as-columns-empty
new file mode 100644 (file)
index 0000000..da48e9b
--- /dev/null
@@ -0,0 +1,2 @@
+COL1   COL3   
+Data1  Data2  Data3
diff --git a/tests/expected/column/table-header-as-columns-json b/tests/expected/column/table-header-as-columns-json
new file mode 100644 (file)
index 0000000..2d6295a
--- /dev/null
@@ -0,0 +1,13 @@
+{
+   "table": [
+      {
+         "name": "Alice",
+         "age": "30",
+         "city": "New York"
+      },{
+         "name": "Bob",
+         "age": "25",
+         "city": "Los Angeles"
+      }
+   ]
+}
index 70fb68926e29ff2ee34a9541a81163d96fb38a4a..4f637204a4c413af8576f2bbabf329eb0d234879 100755 (executable)
@@ -201,4 +201,20 @@ ts_init_subtest "wrap-separator-multiple-separators"
 echo -e 'A:B:C\naa:b1|b2|b3:cc\nxx:y1|y2:zz' | $TS_CMD_COLUMN --table --separator ':' --table-wrap 2 --wrap-separator '|' >> $TS_OUTPUT 2>> $TS_ERRLOG
 ts_finalize_subtest
 
+ts_init_subtest "header-as-columns"
+echo -e 'NAME\tAGE\tCITY\nAlice\t30\tNew York\nBob\t25\tLos Angeles' | $TS_CMD_COLUMN --table -K >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "header-as-columns-csv"
+echo -e 'NAME,AGE,CITY\nAlice,30,New York\nBob,25,Los Angeles' | $TS_CMD_COLUMN --table -K --separator ',' >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "header-as-columns-json"
+echo -e 'NAME,AGE,CITY\nAlice,30,New York\nBob,25,Los Angeles' | $TS_CMD_COLUMN --table -K --separator ',' --json >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
+ts_init_subtest "header-as-columns-empty"
+echo -e 'COL1\t\tCOL3\nData1\tData2\tData3' | $TS_CMD_COLUMN --table -K >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
 ts_finalize