[Midnightbsd-cvs] src [10233] trunk/bin/test: update test

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 2 12:11:13 EDT 2018


Revision: 10233
          http://svnweb.midnightbsd.org/src/?rev=10233
Author:   laffer1
Date:     2018-06-02 12:11:13 -0400 (Sat, 02 Jun 2018)
Log Message:
-----------
update test

Modified Paths:
--------------
    trunk/bin/test/Makefile
    trunk/bin/test/test.1
    trunk/bin/test/test.c

Added Paths:
-----------
    trunk/bin/test/tests/
    trunk/bin/test/tests/Makefile
    trunk/bin/test/tests/legacy_test.sh

Property Changed:
----------------
    trunk/bin/test/test.1

Modified: trunk/bin/test/Makefile
===================================================================
--- trunk/bin/test/Makefile	2018-06-02 16:09:37 UTC (rev 10232)
+++ trunk/bin/test/Makefile	2018-06-02 16:11:13 UTC (rev 10233)
@@ -1,8 +1,15 @@
+# $MidnightBSD$
 #        @(#)Makefile	8.1 (Berkeley) 5/31/93
-# $MidnightBSD: src/bin/test/Makefile,v 1.2 2007/07/26 20:13:02 laffer1 Exp $ 
+# $FreeBSD: stable/10/bin/test/Makefile 262951 2014-03-09 17:04:31Z jmmv $
 
+.include <bsd.own.mk>
+
 PROG=	test
 LINKS=	${BINDIR}/test ${BINDIR}/[
 MLINKS=	test.1 [.1
 
+.if ${MK_TESTS} != "no"
+SUBDIR+=    tests
+.endif
+
 .include <bsd.prog.mk>

Modified: trunk/bin/test/test.1
===================================================================
--- trunk/bin/test/test.1	2018-06-02 16:09:37 UTC (rev 10232)
+++ trunk/bin/test/test.1	2018-06-02 16:11:13 UTC (rev 10233)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"-
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -30,10 +31,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)test.1	8.1 (Berkeley) 5/31/93
-.\" $FreeBSD: src/bin/test/test.1,v 1.23 2005/01/10 08:39:26 imp Exp $
-.\" $MidnightBSD: src/bin/test/test.1,v 1.3 2012/03/09 04:18:38 laffer1 Exp $
+.\" $FreeBSD: stable/10/bin/test/test.1 307423 2016-10-16 23:18:35Z sevan $
 .\"
-.Dd June 1, 2013
+.Dd October 5, 2016
 .Dt TEST 1
 .Os
 .Sh NAME
@@ -44,7 +44,7 @@
 .Nm
 .Ar expression
 .Nm \&[
-.Ar expression Cm ]
+.Ar expression Cm \&]
 .Sh DESCRIPTION
 The
 .Nm
@@ -377,6 +377,11 @@
 and
 .Fl O
 are extensions.
+.Sh HISTORY
+A
+.Nm
+utility appeared in
+.At v7 .
 .Sh BUGS
 Both sides are always evaluated in
 .Fl a


Property changes on: trunk/bin/test/test.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/bin/test/test.c
===================================================================
--- trunk/bin/test/test.c	2018-06-02 16:09:37 UTC (rev 10232)
+++ trunk/bin/test/test.c	2018-06-02 16:11:13 UTC (rev 10233)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: test.c,v 1.21 1999/04/05 09:48:38 kleink Exp $	*/
 
 /*-
@@ -15,7 +16,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/bin/test/test.c 297767 2016-04-09 21:55:58Z jilles $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -67,9 +68,18 @@
 	operand ::= <any legal UNIX file name>
 */
 
+enum token_types {
+	UNOP = 0x100,
+	BINOP = 0x200,
+	BUNOP = 0x300,
+	BBINOP = 0x400,
+	PAREN = 0x500
+};
+
 enum token {
 	EOI,
-	FILRD,
+	OPERAND,
+	FILRD = UNOP + 1,
 	FILWR,
 	FILEX,
 	FILEXIST,
@@ -85,13 +95,13 @@
 	FILSUID,
 	FILSGID,
 	FILSTCK,
-	FILNT,
+	STREZ,
+	STRNZ,
+	FILUID,
+	FILGID,
+	FILNT = BINOP + 1,
 	FILOT,
 	FILEQ,
-	FILUID,
-	FILGID,
-	STREZ,
-	STRNZ,
 	STREQ,
 	STRNE,
 	STRLT,
@@ -102,76 +112,68 @@
 	INTGT,
 	INTLE,
 	INTLT,
-	UNOT,
-	BAND,
+	UNOT = BUNOP + 1,
+	BAND = BBINOP + 1,
 	BOR,
-	LPAREN,
-	RPAREN,
-	OPERAND
+	LPAREN = PAREN + 1,
+	RPAREN
 };
 
-enum token_types {
-	UNOP,
-	BINOP,
-	BUNOP,
-	BBINOP,
-	PAREN
-};
+#define TOKEN_TYPE(token) ((token) & 0xff00)
 
-struct t_op {
-	const char *op_text;
-	short op_num, op_type;
+static struct t_op {
+	char op_text[4];
+	short op_num;
 } const ops [] = {
-	{"-r",	FILRD,	UNOP},
-	{"-w",	FILWR,	UNOP},
-	{"-x",	FILEX,	UNOP},
-	{"-e",	FILEXIST,UNOP},
-	{"-f",	FILREG,	UNOP},
-	{"-d",	FILDIR,	UNOP},
-	{"-c",	FILCDEV,UNOP},
-	{"-b",	FILBDEV,UNOP},
-	{"-p",	FILFIFO,UNOP},
-	{"-u",	FILSUID,UNOP},
-	{"-g",	FILSGID,UNOP},
-	{"-k",	FILSTCK,UNOP},
-	{"-s",	FILGZ,	UNOP},
-	{"-t",	FILTT,	UNOP},
-	{"-z",	STREZ,	UNOP},
-	{"-n",	STRNZ,	UNOP},
-	{"-h",	FILSYM,	UNOP},		/* for backwards compat */
-	{"-O",	FILUID,	UNOP},
-	{"-G",	FILGID,	UNOP},
-	{"-L",	FILSYM,	UNOP},
-	{"-S",	FILSOCK,UNOP},
-	{"=",	STREQ,	BINOP},
-	{"==",	STREQ,	BINOP},
-	{"!=",	STRNE,	BINOP},
-	{"<",	STRLT,	BINOP},
-	{">",	STRGT,	BINOP},
-	{"-eq",	INTEQ,	BINOP},
-	{"-ne",	INTNE,	BINOP},
-	{"-ge",	INTGE,	BINOP},
-	{"-gt",	INTGT,	BINOP},
-	{"-le",	INTLE,	BINOP},
-	{"-lt",	INTLT,	BINOP},
-	{"-nt",	FILNT,	BINOP},
-	{"-ot",	FILOT,	BINOP},
-	{"-ef",	FILEQ,	BINOP},
-	{"!",	UNOT,	BUNOP},
-	{"-a",	BAND,	BBINOP},
-	{"-o",	BOR,	BBINOP},
-	{"(",	LPAREN,	PAREN},
-	{")",	RPAREN,	PAREN},
-	{0,	0,	0}
+	{"-r",	FILRD},
+	{"-w",	FILWR},
+	{"-x",	FILEX},
+	{"-e",	FILEXIST},
+	{"-f",	FILREG},
+	{"-d",	FILDIR},
+	{"-c",	FILCDEV},
+	{"-b",	FILBDEV},
+	{"-p",	FILFIFO},
+	{"-u",	FILSUID},
+	{"-g",	FILSGID},
+	{"-k",	FILSTCK},
+	{"-s",	FILGZ},
+	{"-t",	FILTT},
+	{"-z",	STREZ},
+	{"-n",	STRNZ},
+	{"-h",	FILSYM},		/* for backwards compat */
+	{"-O",	FILUID},
+	{"-G",	FILGID},
+	{"-L",	FILSYM},
+	{"-S",	FILSOCK},
+	{"=",	STREQ},
+	{"==",	STREQ},
+	{"!=",	STRNE},
+	{"<",	STRLT},
+	{">",	STRGT},
+	{"-eq",	INTEQ},
+	{"-ne",	INTNE},
+	{"-ge",	INTGE},
+	{"-gt",	INTGT},
+	{"-le",	INTLE},
+	{"-lt",	INTLT},
+	{"-nt",	FILNT},
+	{"-ot",	FILOT},
+	{"-ef",	FILEQ},
+	{"!",	UNOT},
+	{"-a",	BAND},
+	{"-o",	BOR},
+	{"(",	LPAREN},
+	{")",	RPAREN},
+	{"",	0}
 };
 
-struct t_op const *t_wp_op;
-int nargc;
-char **t_wp;
-int parenlevel;
+static int nargc;
+static char **t_wp;
+static int parenlevel;
 
 static int	aexpr(enum token);
-static int	binop(void);
+static int	binop(enum token);
 static int	equalf(const char *, const char *);
 static int	filstat(char *, enum token);
 static int	getn(const char *);
@@ -295,10 +297,10 @@
 		parenlevel--;
 		return res;
 	}
-	if (t_wp_op && t_wp_op->op_type == UNOP) {
+	if (TOKEN_TYPE(n) == UNOP) {
 		/* unary expression */
 		if (--nargc == 0)
-			syntax(t_wp_op->op_text, "argument expected");
+			syntax(NULL, "argument expected"); /* impossible */
 		switch (n) {
 		case STREZ:
 			return strlen(*++t_wp) == 0;
@@ -311,28 +313,25 @@
 		}
 	}
 
-	if (t_lex(nargc > 0 ? t_wp[1] : NULL), t_wp_op && t_wp_op->op_type ==
-	    BINOP) {
-		return binop();
-	}
+	nn = t_lex(nargc > 0 ? t_wp[1] : NULL);
+	if (TOKEN_TYPE(nn) == BINOP)
+		return binop(nn);
 
 	return strlen(*t_wp) > 0;
 }
 
 static int
-binop(void)
+binop(enum token n)
 {
-	const char *opnd1, *opnd2;
-	struct t_op const *op;
+	const char *opnd1, *op, *opnd2;
 
 	opnd1 = *t_wp;
-	(void) t_lex(nargc > 0 ? (--nargc, *++t_wp) : NULL);
-	op = t_wp_op;
+	op = nargc > 0 ? (--nargc, *++t_wp) : NULL;
 
 	if ((opnd2 = nargc > 0 ? (--nargc, *++t_wp) : NULL) == NULL)
-		syntax(op->op_text, "argument expected");
+		syntax(op, "argument expected");
 
-	switch (op->op_num) {
+	switch (n) {
 	case STREQ:
 		return strcmp(opnd1, opnd2) == 0;
 	case STRNE:
@@ -424,22 +423,20 @@
 	struct t_op const *op = ops;
 
 	if (s == 0) {
-		t_wp_op = NULL;
 		return EOI;
 	}
-	while (op->op_text) {
+	while (*op->op_text) {
 		if (strcmp(s, op->op_text) == 0) {
-			if (((op->op_type == UNOP || op->op_type == BUNOP)
+			if (((TOKEN_TYPE(op->op_num) == UNOP ||
+			    TOKEN_TYPE(op->op_num) == BUNOP)
 						&& isunopoperand()) ||
 			    (op->op_num == LPAREN && islparenoperand()) ||
 			    (op->op_num == RPAREN && isrparenoperand()))
 				break;
-			t_wp_op = op;
 			return op->op_num;
 		}
 		op++;
 	}
-	t_wp_op = NULL;
 	return OPERAND;
 }
 
@@ -456,9 +453,9 @@
 	if (nargc == 2)
 		return parenlevel == 1 && strcmp(s, ")") == 0;
 	t = *(t_wp + 2);
-	while (op->op_text) {
+	while (*op->op_text) {
 		if (strcmp(s, op->op_text) == 0)
-			return op->op_type == BINOP &&
+			return TOKEN_TYPE(op->op_num) == BINOP &&
 			    (parenlevel == 0 || t[0] != ')' || t[1] != '\0');
 		op++;
 	}
@@ -478,9 +475,9 @@
 		return parenlevel == 1 && strcmp(s, ")") == 0;
 	if (nargc != 3)
 		return 0;
-	while (op->op_text) {
+	while (*op->op_text) {
 		if (strcmp(s, op->op_text) == 0)
-			return op->op_type == BINOP;
+			return TOKEN_TYPE(op->op_num) == BINOP;
 		op++;
 	}
 	return 0;

Added: trunk/bin/test/tests/Makefile
===================================================================
--- trunk/bin/test/tests/Makefile	                        (rev 0)
+++ trunk/bin/test/tests/Makefile	2018-06-02 16:11:13 UTC (rev 10233)
@@ -0,0 +1,14 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/bin/test/tests/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+TAP_TESTS_SH=	legacy_test
+# Some tests in here are silently not run when the tests are executed as
+# root.  Explicitly tell Kyua to drop privileges.
+#
+# TODO(jmmv): Kyua needs to do this by default, not only when explicitly
+# requested.  See https://code.google.com/p/kyua/issues/detail?id=6
+TEST_METADATA.legacy_test+= required_user="unprivileged"
+
+.include <bsd.test.mk>


Property changes on: trunk/bin/test/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/bin/test/tests/legacy_test.sh
===================================================================
--- trunk/bin/test/tests/legacy_test.sh	                        (rev 0)
+++ trunk/bin/test/tests/legacy_test.sh	2018-06-02 16:11:13 UTC (rev 10233)
@@ -0,0 +1,197 @@
+#!/bin/sh
+
+#-
+# Copyright (c) June 1996 Wolfram Schneider <wosch at FreeBSD.org>. Berlin.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+#
+# TEST.sh - check if test(1) or builtin test works
+#
+# $FreeBSD: stable/10/bin/test/tests/legacy_test.sh 289969 2015-10-26 00:05:02Z ngie $
+# $MidnightBSD$
+
+# force a specified test program, e.g. `env test=/bin/test sh regress.sh'
+: ${test=test}
+
+t ()
+{
+	# $1 -> exit code
+	# $2 -> $test expression
+
+	count=$((count+1))
+	# check for syntax errors
+	syntax="`eval $test $2 2>&1`"
+	ret=$?
+	if test -n "$syntax"; then
+		printf "not ok %s - (syntax error)\n" "$count $2"
+	elif [ "$ret" != "$1" ]; then
+		printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
+	else
+		printf "ok %s\n" "$count $2"
+	fi
+}
+
+count=0
+echo "1..130"
+
+t 0 'b = b'
+t 0 'b == b'
+t 1 'b != b'
+t 0 '\( b = b \)'
+t 0 '\( b == b \)'
+t 1 '! \( b = b \)'
+t 1 '! \( b == b \)'
+t 1 '! -f /etc/passwd'
+
+t 0 '-h = -h'
+t 0 '-o = -o'
+t 1 '-f = h'
+t 1 '-h = f'
+t 1 '-o = f'
+t 1 'f = -o'
+t 0 '\( -h = -h \)'
+t 1 '\( a = -h \)'
+t 1 '\( -f = h \)'
+t 0 '-h = -h -o a'
+t 0 '\( -h = -h \) -o 1'
+t 0 '-h = -h -o -h = -h'
+t 0 '\( -h = -h \) -o \( -h = -h \)'
+t 0 'roedelheim = roedelheim'
+t 1 'potsdam = berlin-dahlem'
+
+t 0 '-d /'
+t 0 '-d / -a a != b'
+t 1 '-z "-z"'
+t 0 '-n -n'
+
+t 0 '0'
+t 0 '\( 0 \)'
+t 0 '-E'
+t 0 '-X -a -X'
+t 0 '-XXX'
+t 0 '\( -E \)'
+t 0 'true -o X'
+t 0 'true -o -X'
+t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
+t 1 '-h /'
+t 0 '-r /'
+t 1 '-w /'
+t 0 '-x /bin/sh'
+t 0 '-c /dev/null'
+t 0 '-f /etc/passwd'
+t 0 '-s /etc/passwd'
+
+t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
+t 0 '100 -eq 100'
+t 0 '100 -lt 200'
+t 1 '1000 -lt 200'
+t 0 '1000 -gt 200'
+t 0 '1000 -ge 200'
+t 0 '1000 -ge 1000'
+t 1 '2 -ne 2'
+t 0 '0 -eq 0'
+t 1 '-5 -eq 5'
+t 0 '\( 0 -eq 0 \)'
+t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
+
+t 1 '"" -o ""'
+t 1 '"" -a ""'
+t 1 '"a" -a ""'
+t 0 '"a" -a ! ""'
+t 1 '""'
+t 0 '! ""'
+
+t 0 '!'
+t 0 '\('
+t 0 '\)'
+
+t 1 '\( = \)'
+t 0 '\( != \)'
+t 0 '\( ! \)'
+t 0 '\( \( \)'
+t 0 '\( \) \)'
+t 0 '! = !'
+t 1 '! != !'
+t 1 '-n = \)'
+t 0 '! != \)'
+t 1 '! = a'
+t 0 '! != -n'
+t 0 '! -c /etc/passwd'
+
+t 1 '! = = ='
+t 0 '! = = \)'
+t 0 '! "" -o ""'
+t 1 '! "x" -o ""'
+t 1 '! "" -o "x"'
+t 1 '! "x" -o "x"'
+t 0 '\( -f /etc/passwd \)'
+t 0 '\( ! "" \)'
+t 1 '\( ! -e \)'
+
+t 0 '0 -eq 0 -a -d /'
+t 0 '-s = "" -o "" = ""'
+t 0 '"" = "" -o -s = ""'
+t 1 '-s = "" -o -s = ""'
+t 0 '-z x -o x = "#" -o x = x'
+t 1 '-z y -o y = "#" -o y = x'
+t 0 '0 -ne 0 -o ! -f /'
+t 0 '1 -ne 0 -o ! -f /etc/passwd'
+t 1 '0 -ne 0 -o ! -f /etc/passwd'
+
+t 0 '-n ='
+t 1 '-z ='
+t 1 '! ='
+t 0 '-n -eq'
+t 1 '-z -eq'
+t 1 '! -eq'
+t 0 '-n -a'
+t 1 '-z -a'
+t 1 '! -a'
+t 0 '-n -o'
+t 1 '-z -o'
+t 1 '! -o'
+t 1 '! -n ='
+t 0 '! -z ='
+t 0 '! ! ='
+t 1 '! -n -eq'
+t 0 '! -z -eq'
+t 0 '! ! -eq'
+t 1 '! -n -a'
+t 0 '! -z -a'
+t 0 '! ! -a'
+t 1 '! -n -o'
+t 0 '! -z -o'
+t 0 '! ! -o'
+t 0 '\( -n = \)'
+t 1 '\( -z = \)'
+t 1 '\( ! = \)'
+t 0 '\( -n -eq \)'
+t 1 '\( -z -eq \)'
+t 1 '\( ! -eq \)'
+t 0 '\( -n -a \)'
+t 1 '\( -z -a \)'
+t 1 '\( ! -a \)'
+t 0 '\( -n -o \)'
+t 1 '\( -z -o \)'
+t 1 '\( ! -o \)'


Property changes on: trunk/bin/test/tests/legacy_test.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list