Subject: Re: bin/33995: /usr/bin/cut is not conformant to SUSv3
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, cheusov@tut.by>
From: Aleksey Cheusov <cheusov@tut.by>
List: netbsd-bugs
Date: 07/26/2006 19:10:02
The following reply was made to PR bin/33995; it has been noted by GNATS.

From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/33995: /usr/bin/cut is not conformant to SUSv3
Date: Wed, 26 Jul 2006 22:10:21 +0300

 --=-=-=
 
 
 While rewriting cut (actually, cut -f) that has no limitations in input
 line length and doesn't use BSD-ism fgetln I created regression tests
 for 'cut -f'. I hope you'll find them helpful.
 
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=cut.regress.diff
 Content-Description: regression tests for cut -f
 
 ? cut/result
 Index: cut/Makefile
 ===================================================================
 RCS file: cut/Makefile
 diff -N cut/Makefile
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ cut/Makefile	26 Jul 2006 18:59:25 -0000
 @@ -0,0 +1,8 @@
 +#	$NetBSD$
 +
 +NOMAN=  	# defined
 +
 +regress:
 +	@${HOST_SH} ${.CURDIR}/cut_tests
 +
 +.include <bsd.prog.mk>
 Index: cut/cut_tests
 ===================================================================
 RCS file: cut/cut_tests
 diff -N cut/cut_tests
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ cut/cut_tests	26 Jul 2006 18:59:25 -0000
 @@ -0,0 +1,27 @@
 +#!/bin/sh
 +
 +run_cut (){
 +    echo "-----test: cut $@---------"
 +    cut "$@"
 +}
 +
 +run_test_block (){
 +    run_cut -f 1 "$@"
 +    run_cut -f 2 "$@"
 +    run_cut -f 3 "$@"
 +    run_cut -f 1-2 "$@"
 +    run_cut -f 2,3 "$@"
 +    run_cut -f 4 "$@"
 +    run_cut -f 1-3,4-7 "$@"
 +    run_cut -f 1,2-7 "$@"
 +}
 +
 +run_all_tests (){
 +    run_test_block "$@"
 +    run_test_block -s "$@"
 +    run_test_block -d ':' "$@"
 +    run_test_block -d ':' -s "$@"
 +}
 +
 +run_all_tests input >result
 +cmp -s result expected
 Index: cut/expected
 ===================================================================
 RCS file: cut/expected
 diff -N cut/expected
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ cut/expected	26 Jul 2006 18:59:25 -0000
 @@ -0,0 +1,240 @@
 +-----test: cut -f 1 input ---------
 +1
 +
 +12
 +
 +qwe
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 2 input ---------
 +1
 +
 +34
 +12
 +
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 3 input ---------
 +1
 +
 +56
 +
 +rty
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 1-2 input ---------
 +1
 +
 +12	34
 +	12
 +qwe	
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 2,3 input ---------
 +1
 +
 +34	56
 +12	
 +	rty
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 4 input ---------
 +1
 +
 +
 +34
 +uio
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 1-3,4-7 input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd	
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 1,2-7 input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd	
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 +-----test: cut -f 1 -s input ---------
 +12
 +
 +qwe
 +-----test: cut -f 2 -s input ---------
 +34
 +12
 +
 +-----test: cut -f 3 -s input ---------
 +56
 +
 +rty
 +-----test: cut -f 1-2 -s input ---------
 +12	34
 +	12
 +qwe	
 +-----test: cut -f 2,3 -s input ---------
 +34	56
 +12	
 +	rty
 +-----test: cut -f 4 -s input ---------
 +
 +34
 +uio
 +-----test: cut -f 1-3,4-7 -s input ---------
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd	
 +-----test: cut -f 1,2-7 -s input ---------
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd	
 +-----test: cut -f 1 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +12
 +qwe
 +
 +-----test: cut -f 2 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +34
 +rty
 +qwe
 +-----test: cut -f 3 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +56
 +uio
 +
 +-----test: cut -f 1-2 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +12:34
 +qwe:rty
 +:qwe
 +-----test: cut -f 2,3 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +34:56
 +rty:uio
 +qwe:
 +-----test: cut -f 4 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +
 +p[]
 +
 +-----test: cut -f 1-3,4-7 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl
 +:qwe:::rty:uio:
 +-----test: cut -f 1,2-7 -d : input ---------
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl
 +:qwe:::rty:uio:
 +-----test: cut -f 1 -d : -s input ---------
 +12
 +qwe
 +
 +-----test: cut -f 2 -d : -s input ---------
 +34
 +rty
 +qwe
 +-----test: cut -f 3 -d : -s input ---------
 +56
 +uio
 +
 +-----test: cut -f 1-2 -d : -s input ---------
 +12:34
 +qwe:rty
 +:qwe
 +-----test: cut -f 2,3 -d : -s input ---------
 +34:56
 +rty:uio
 +qwe:
 +-----test: cut -f 4 -d : -s input ---------
 +
 +p[]
 +
 +-----test: cut -f 1-3,4-7 -d : -s input ---------
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl
 +:qwe:::rty:uio:
 +-----test: cut -f 1,2-7 -d : -s input ---------
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl
 +:qwe:::rty:uio:
 Index: cut/input
 ===================================================================
 RCS file: cut/input
 diff -N cut/input
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ cut/input	26 Jul 2006 18:59:25 -0000
 @@ -0,0 +1,10 @@
 +1
 +
 +12	34	56
 +	12		34	56
 +qwe		rty	uio	p[]	asd		fgh	jkl	zxc	vbn	nm
 +1
 +
 +12:34:56
 +qwe:rty:uio:p[]:asd:fgh:jkl:zxc:vbn:nm
 +:qwe:::rty:uio::p[]:asd:fgh:jkl:zxc:vbn:nm
 
 --=-=-=
 
 
 If you need 'cut -f' code without fgetln, let me know.
 
 -- 
 Best regards, Aleksey Cheusov.
 
 --=-=-=--