Open brewmanz opened 2 years ago
Looking further, it seems to have actually compiled, but maybe not installed properly. Makefile contains these lines:
PREFIX=/usr
LIBDIR=$(PREFIX)/lib/gawk
AWKDIR=$(PREFIX)/share/awk
Now, folder /usr/share/awk
exists, and has an entry /usr/share/awk/awkunit.awk
in it (created today).
However, folder /usr/lib/gawk
does NOT exist, but file /usr/lib/gawk
DOES exist (17.4K), created today.
My suspicion is that file awkunit.so
has been copied, not into (non existent) folder /usr/lib/gawk
, but as a file of the same name.
I have tried various options, but am working at (beyond?) my limit of understanding. Still not working. I am getting:
~/git/awkunit/examples$ locate awkunit.so
/home/xxx/git/awkunit/awkunit.so
/usr/lib/awkunit.so
~/git/awkunit/examples$ ./test_asort.awk
awk: In file included from ./test_asort.awk:2:
awk: awkunit:2: error: can't open shared library `awkunit.so' for reading (No such file or directory)
~/git/awkunit/examples$ cd ..
~/git/awkunit$ ./examples/test_asort.awk
awk: In file included from ./examples/test_asort.awk:2:
awk: awkunit:2: error: can't open shared library `awkunit.so' for reading (No such file or directory)
I have checked various changes I've made, and now backed out my awkunit.awk modification from
@load "awkunit.so"
back to original
@load "awkunit"
so now error is
awk: awkunit:2: error: can't open shared library `awkunit' for reading (No such file or directory)
OK. This is what worked for me; YMMV:
diff --git a/Makefile b/Makefile
index 784e513..6eef6ab 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
PREFIX=/usr
-LIBDIR=$(PREFIX)/lib/gawk
+LIBDIR=$(PREFIX)/lib/x86_64-linux-gnu/gawk
AWKDIR=$(PREFIX)/share/awk
CC=gcc
diff --git a/awkunit.c b/awkunit.c
index be0004b..941dec2 100644
--- a/awkunit.c
+++ b/awkunit.c
@@ -30,20 +30,22 @@
static awk_bool_t (*init_func)(void) = NULL;
-static awk_value_t *do_assertIO(int nargs, awk_value_t *result)
+#define DO_ASSERTIO_MAX_ARGS 3
+#define DO_ASSERTIO_MIN_ARGS 3
+static awk_value_t *do_assertIO(int nargs, awk_value_t *result, awk_ext_func_t *ext_func)
{
awk_value_t scriptFile, inFile, outFile;
int ret = -1;
FILE *fpipe, *fo;
char *command = NULL, pbuf[BUFFER_SIZE], obuf[BUFFER_SIZE];
-
+
assert(result != NULL);
-
+
if (do_lint && nargs != 3)
lintwarn(ext_id,
- _("assertIO: called with incorrect number of arguments, "
+ _("awkunit::assertIO: called with incorrect number of arguments, "
"expecting 3"));
-
+
if (get_argument(0, AWK_STRING, &scriptFile) &&
get_argument(1, AWK_STRING, &inFile) &&
get_argument(2, AWK_STRING, &outFile)) {
@@ -58,7 +60,7 @@
strcat(command, scriptFile.str_value.str);
strcat(command, " < ");
strcat(command, inFile.str_value.str);
-
+
if (!(fpipe = (FILE *)popen(command, "r"))) {
perror("Fatal error: cannot open pipe");
exit(-1);
@@ -67,7 +69,7 @@
perror("Fatal error: cannot open file");
exit(-1);
}
-
+
while (fgets(pbuf, BUFFER_SIZE, fpipe)) {
fgets(obuf, BUFFER_SIZE, fo);
if (strcmp(pbuf, obuf) != 0) {
@@ -79,14 +81,14 @@
exit(-1);
}
}
-
+
pclose(fpipe);
fclose(fo);
return make_number(ret, result);
}
static awk_ext_func_t func_table[] = {
- {"assertIO", do_assertIO, 3},
+ {"assertIO", do_assertIO, DO_ASSERTIO_MAX_ARGS, DO_ASSERTIO_MIN_ARGS},
};
-dl_load_func(func_table, some_name, "name_space_in_quotes")
+dl_load_func(func_table, some_name, "awkunit")
diff --git a/examples/test_asort.awk b/examples/test_asort.awk
index 2bc4321..cb10a31 100755
--- a/examples/test_asort.awk
+++ b/examples/test_asort.awk
@@ -3,7 +3,7 @@
@include "asort"
function testIO() {
- assertIO("asort.awk", "/dev/stdin", "asort.ok")
+ awkunit::assertIO("asort.awk", "/dev/stdin", "asort.ok")
}
BEGIN {
diff --git a/examples/test_sum.awk b/examples/test_sum.awk
index 37d10f2..79d05b3 100755
--- a/examples/test_sum.awk
+++ b/examples/test_sum.awk
@@ -10,7 +10,7 @@
}
function testIO() {
- assertIO("sum.awk", "sum.in", "sum.ok")
+ awkunit::assertIO("sum.awk", "sum.in", "sum.ok")
}
BEGIN {
When trying to compile, I get:
The actve folder:
The gawk source folder: