From: kostasch Date: Wed, 2 Sep 2020 17:54:48 +0300 Subject: [PATCH] Fixed the bug where not all tests ran properly with make check. 2020-09-02 Kostas Chasialis * testsuite/poke.libpoke/values.c: Now all tests run with make check. * testsuite/poke.libpoke/Makefile.am: Added TESTDIR for this purpose. --- ChangeLog | 5 +++++ testsuite/poke.libpoke/Makefile.am | 1 + testsuite/poke.libpoke/values.c | 30 ++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92a3ae73..1d8b8dd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-09-02 Kostas Chasialis + + * testsuite/poke.libpoke/values.c: Now all tests run with make check. + * testsuite/poke.libpoke/Makefile.am: Added TESTDIR for this purpose. + 2020-09-02 Jose E. Marchesi * libpoke/pkl-typify.c (pkl_typify2_ps_type): Do not set diff --git a/testsuite/poke.libpoke/Makefile.am b/testsuite/poke.libpoke/Makefile.am index 3d47507d..8ebb10c8 100644 --- a/testsuite/poke.libpoke/Makefile.am +++ b/testsuite/poke.libpoke/Makefile.am @@ -23,6 +23,7 @@ values_SOURCES = $(COMMON) values.c values_CPPFLAGS = -I$(top_builddir)/gl -I$(top_srcdir)/gl \ -I$(top_srcdir)/common \ + -DTESTDIR=\"$(srcdir)/poke.libpoke\" \ -DPKGDATADIR=\"$(pkgdatadir)\" \ -I$(top_srcdir)/libpoke -I$(top_builddir)/libpoke diff --git a/testsuite/poke.libpoke/values.c b/testsuite/poke.libpoke/values.c index 495f423f..699a6750 100644 --- a/testsuite/poke.libpoke/values.c +++ b/testsuite/poke.libpoke/values.c @@ -220,7 +220,7 @@ test_pk_equal_file (const char *filename, FILE *ifp) if (compile_poke_expressions (ifp, pkc, &val1, &val2) == 0) goto error; - /* (NOTE: kostas) We should have a way to discriminate if we should check + /* We should have a way to discriminate if we should check if 2 values should match or not. Currently, this decision is taken based on the name of the file. @@ -253,27 +253,45 @@ test_pk_val_equal_p () DIR *directory; struct dirent *dir; const char *extension; + char *testdir, *testfile; + size_t testdir_len; - directory = opendir ("."); + testdir_len = strlen (TESTDIR); + testdir = (char *) malloc (testdir_len + 2); + memcpy (testdir, TESTDIR, testdir_len + 1); + strncat (testdir, "/", 1); + testdir_len = strlen (testdir); + + directory = opendir (testdir); if (directory) { while ((dir = readdir (directory)) != NULL) { - /* If this file a .json file, proccess it. */ + /* If this file a .test file, proccess it. */ extension = strrchr (dir->d_name, '.'); if (extension) { if (!strncmp (extension + 1, "test", 4)) { - ifp = fopen (dir->d_name, "r"); + testfile = (char *) malloc (testdir_len + + strlen (dir->d_name) + 1); + memcpy (testfile, testdir, testdir_len + 1); + strncat (testfile, dir->d_name, strlen (dir->d_name)); + + ifp = fopen (testfile, "r"); if (ifp) - test_pk_equal_file (dir->d_name, ifp); - fclose (ifp); + { + test_pk_equal_file (dir->d_name, ifp); + fclose (ifp); + } + free (testfile); } } } closedir (directory); } + + free (testdir); } int -- 2.17.1