Added support for ignoring '-g' per GNU ls, thanks to David Vrabel
[oweals/busybox.git] / test.c
diff --git a/test.c b/test.c
index 85d06a83a7f8f0ec552cdd79bb2fde4757653bd8..36da4db0b76ad8c98d43163a856bb1fedb43f1b9 100644 (file)
--- a/test.c
+++ b/test.c
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * echo implementation for busybox
+ * test implementation for busybox
  *
  * Copyright (c) by a whole pile of folks: 
  *
@@ -39,6 +39,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#define BB_DECLARE_EXTERN
+#define bb_need_help
+#include "messages.c"
 
 /* test(1) accepts the following grammar:
        oexpr   ::= aexpr | aexpr "-o" oexpr ;
@@ -182,9 +185,18 @@ test_main(int argc, char** argv)
 
        if (strcmp(argv[0], "[") == 0) {
                if (strcmp(argv[--argc], "]"))
-                       fatalError("missing ]");
+                       fatalError("missing ]\n");
                argv[argc] = NULL;
        }
+       if (strcmp(argv[1], dash_dash_help) == 0) {
+               usage("test EXPRESSION\n"
+                         "or   [ EXPRESSION ]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+                               "\nChecks file types and compares values returning an exit\n"
+                               "code determined by the value of EXPRESSION.\n"
+#endif
+                               );
+       }
 
        /* Implement special cases from POSIX.2, section 4.62.4 */
        switch (argc) {
@@ -223,7 +235,7 @@ test_main(int argc, char** argv)
        if (*t_wp != NULL && *++t_wp != NULL)
                syntax(*t_wp, "unknown operand");
 
-       exit( res);
+       return( res);
 }
 
 static void
@@ -232,9 +244,9 @@ syntax(op, msg)
        char    *msg;
 {
        if (op && *op)
-               fatalError("%s: %s", op, msg);
+               fatalError("%s: %s\n", op, msg);
        else
-               fatalError("%s", msg);
+               fatalError("%s\n", msg);
 }
 
 static int
@@ -469,13 +481,13 @@ getn(s)
        r = strtol(s, &p, 10);
 
        if (errno != 0)
-         fatalError("%s: out of range", s);
+         fatalError("%s: out of range\n", s);
 
        while (isspace(*p))
          p++;
        
        if (*p)
-         fatalError("%s: bad number", s);
+         fatalError("%s: bad number\n", s);
 
        return (int) r;
 }
@@ -555,7 +567,7 @@ initialize_group_array ()
 {
        ngroups = getgroups(0, NULL);
        if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
-               fatalError("Out of space");
+               fatalError("Out of space\n");
 
        getgroups(ngroups, group_array);
 }