From: kostasch Date: Fri, 4 Sep 2020 20:51:16 +0300 Subject: [PATCH] Bugfix where not all tests ran properly with make check. 2020-09-04 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 | 29 +++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73164c1c..4078dcb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-09-04 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-04 Jose E. Marchesi * libpoke/pkl.c (rest_of_compilation): Revert fold and trans4 in diff --git a/testsuite/poke.libpoke/Makefile.am b/testsuite/poke.libpoke/Makefile.am index 3d47507d..1a9312da 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=\"$(abs_srcdir)\" \ -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..2fe3cd75 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,44 @@ 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. */ 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