Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses tests/libcurses: remove include path han...



details:   https://anonhg.NetBSD.org/src/rev/1764f3389545
branches:  trunk
changeset: 980634:1764f3389545
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 13 08:00:07 2021 +0000

description:
tests/libcurses: remove include path handling

All include commands in the current test suite use relative paths.
Instead of a fixed include path, interpret the included filename
relative to the including file.

diffstat:

 tests/lib/libcurses/director/director.c      |  17 +----------
 tests/lib/libcurses/director/testlang_conf.l |  41 ++++++++++++++-------------
 tests/lib/libcurses/t_curses.sh              |   1 -
 3 files changed, 23 insertions(+), 36 deletions(-)

diffs (152 lines):

diff -r 65920e87891a -r 1764f3389545 tests/lib/libcurses/director/director.c
--- a/tests/lib/libcurses/director/director.c   Sat Feb 13 07:57:09 2021 +0000
+++ b/tests/lib/libcurses/director/director.c   Sat Feb 13 08:00:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: director.c,v 1.23 2021/02/13 07:32:19 rillig Exp $     */
+/*     $NetBSD: director.c,v 1.24 2021/02/13 08:00:07 rillig Exp $     */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -51,7 +51,6 @@
 #define DEF_SLAVE "./slave"
 
 const char *def_check_path = "./"; /* default check path */
-const char *def_include_path = "./"; /* default include path */
 
 extern size_t nvars;           /* In testlang_conf.y */
 saved_data_t  saved_output;    /* In testlang_conf.y */
@@ -62,7 +61,6 @@
 int check_file_flag;           /* control check-file generation */
 const char *check_path;                /* path to prepend to check files for output
                                   validation */
-const char *include_path;      /* path to prepend to include files */
 char *cur_file;                        /* name of file currently being read */
 
 void init_parse_variables(int);        /* in testlang_parse.y */
@@ -142,11 +140,8 @@
        verbose = 0;
        check_file_flag = 0;
 
-       while ((ch = getopt(argc, argv, "vgfC:I:p:s:t:T:")) != -1) {
+       while ((ch = getopt(argc, argv, "vgfC:p:s:t:T:")) != -1) {
                switch (ch) {
-               case 'I':
-                       include_path = optarg;
-                       break;
                case 'C':
                        check_path = optarg;
                        break;
@@ -199,14 +194,6 @@
                check_path = def_check_path;
        }
 
-       if (include_path == NULL)
-               include_path = getenv("INCLUDE_PATH");
-       if ((include_path == NULL) || (include_path[0] == '\0')) {
-               warnx("$INCLUDE_PATH not set, defaulting to %s",
-                       def_include_path);
-               include_path = def_include_path;
-       }
-
        signal(SIGCHLD, slave_died);
 
        if (setenv("TERM", term, 1) != 0)
diff -r 65920e87891a -r 1764f3389545 tests/lib/libcurses/director/testlang_conf.l
--- a/tests/lib/libcurses/director/testlang_conf.l      Sat Feb 13 07:57:09 2021 +0000
+++ b/tests/lib/libcurses/director/testlang_conf.l      Sat Feb 13 08:00:07 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_conf.l,v 1.18 2021/02/08 23:54:03 rillig Exp $        */
+/*     $NetBSD: testlang_conf.l,v 1.19 2021/02/13 08:00:07 rillig Exp $        */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -45,7 +45,6 @@
 int yylex(void);
 
 extern size_t line;
-extern char *include_path;     /* from director.c */
 extern char *cur_file;         /* from director.c */
 
 static int include_stack[MAX_INCLUDES];
@@ -175,7 +174,7 @@
 
 <incl>[ \t]*   /* eat the whitespace */
 <incl>[^ \t\n]+ { /* got the include file name */
-               char inc_file[MAXPATHLEN];
+               char *inc_file;
 
                if (include_ptr > MAX_INCLUDES) {
                        fprintf(stderr,
@@ -184,23 +183,27 @@
                                exit(2);
                }
 
-               if (yytext[0] != '/') {
-                       if (strlcpy(inc_file, include_path, sizeof(inc_file))
-                           >= sizeof(inc_file))
-                               err(2, "CHECK_PATH too long");
-                       if ((include_path[strlen(include_path) - 1] != '/') &&
-                           ((strlcat(inc_file, "/", sizeof(inc_file))
-                           >= sizeof(inc_file))))
-                               err(2, "Could not append / to include file path");
+               const char *dir_begin;
+               int dir_len;
+               if (yytext[0] == '/') {
+                       dir_begin = "";
+                       dir_len = 0;
                } else {
-                       inc_file[0] = '\0';
+                       dir_begin = cur_file;
+                       const char *dir_end = strrchr(cur_file, '/');
+                       if (dir_end != NULL) {
+                               dir_len = (int)(dir_end + 1 - dir_begin);
+                       } else {
+                               dir_begin = ".";
+                               dir_len = 1;
+                       }
                }
 
-               if (strlcat(inc_file, yytext, sizeof(inc_file))
-                   >= sizeof(inc_file))
-                       err(2, "Path to include file path overflowed");
+               if (asprintf(&inc_file, "%.*s%s",
+                   dir_len, dir_begin, yytext) == -1)
+                       err(2, "Cannot construct include path");
 
-               yyin = fopen(inc_file, "r" );
+               yyin = fopen(inc_file, "r");
 
                if (!yyin)
                        err(1, "Error opening %s", inc_file);
@@ -209,9 +212,7 @@
 
                include_stack[include_ptr] = line;
                include_files[include_ptr++] = cur_file;
-               cur_file = strdup(inc_file);
-               if (cur_file == NULL)
-                       err(2, "Cannot allocate new include file string");
+               cur_file = inc_file;
                line = 1;
                BEGIN(INITIAL);
        }
@@ -336,7 +337,7 @@
                        rv = yylval.retval->data_value;
                        for (i = 0; i < len; i += 2)
                                *rv++ = (str[i] << 8) | str[i+1];
-                       *rv = __NORMAL | '\0'; /* terminates chtype array */    
+                       *rv = __NORMAL | '\0'; /* terminates chtype array */
                        yylval.retval->data_type = data_byte;
                        yylval.retval->data_len = chlen;
                        return BYTE;
diff -r 65920e87891a -r 1764f3389545 tests/lib/libcurses/t_curses.sh
--- a/tests/lib/libcurses/t_curses.sh   Sat Feb 13 07:57:09 2021 +0000
+++ b/tests/lib/libcurses/t_curses.sh   Sat Feb 13 08:00:07 2021 +0000
@@ -25,7 +25,6 @@
        $(atf_get_srcdir)/director $2 \
                -T $(atf_get_srcdir) \
                -t atf \
-               -I $(atf_get_srcdir)/tests \
                -C $(atf_get_srcdir)/check_files \
                -s $(atf_get_srcdir)/slave $file || atf_fail "test ${file} failed"
 }



Home | Main Index | Thread Index | Old Index