From 819aa9eba741c36bb522cbc2c7f10e24d190f945 Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Fri, 20 Nov 2009 15:24:07 +0000 Subject: join: add --header option to always output the first line This essentially allows one to use --check-order with headings. Note join without --check-order will already handle the common case where headings do match in each file, however using --check-order will fail often when the header sorts after the first line of data. Note also that this will join header lines from each file even if they don't match, with headings from the first file being used. * NEWS: Mention the new option. * doc/coreutils.texi (join invocation): Describe the new option. * src/join.c (usage): Likewise. (join): Join the header lines unconditionally. * tests/misc/join: Add 5 new tests. --- tests/misc/join | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/misc/join b/tests/misc/join index 49194e046..4e7798fd9 100755 --- a/tests/misc/join +++ b/tests/misc/join @@ -185,6 +185,34 @@ my @tv = ( # Before 6.10.143, this would mistakenly fail with the diagnostic: # join: File 1 is not in sorted order ['chkodr-7', '-12', ["2 a\n1 b\n", ""], "", 0], + +# Test '--header' feature +['header-1', '--header', + [ "ID Name\n1 A\n2 B\n", "ID Color\n1 red\n"], "ID Name Color\n1 A red\n", 0], + +# '--header' with '--check-order' : The header line is out-of-order but the +# actual data is in order. This join should succeed. +['header-2', '--header --check-order', + ["ID Name\n1 A\n2 B\n", "ID Color\n2 green\n"], + "ID Name Color\n2 B green\n", 0], + +# '--header' with '--check-order' : The header line is out-of-order AND the +# actual data out-of-order. This join should fail. +['header-3', '--header --check-order', + ["ID Name\n2 B\n1 A\n", "ID Color\n2 blue\n"], "ID Name Color\n", 1, + "$prog: file 1 is not in sorted order\n"], + +# '--header' with specific output format '-o'. +# output header line should respect the requested format +['header-4', '--header -o "0,1.3,2.2"', + ["ID Group Name\n1 Foo A\n2 Bar B\n", "ID Color\n2 blue\n"], + "ID Name Color\n2 B blue\n", 0], + +# '--header' always outputs headers from the first file +# even if the headers from the second file don't match +['header-5', '--header', + [ "ID1 Name\n1 A\n2 B\n", "ID2 Color\n1 red\n"], "ID1 Name Color\n1 A red\n", 0], + ); # Convert the above old-style test vectors to the newer -- cgit v1.2.3-54-g00ecf