2020-12-01 10:22:17 +00:00
|
|
|
@pragma entry main
|
|
|
|
@pragma implicit off
|
|
|
|
|
2022-04-08 03:42:20 +00:00
|
|
|
@include "tap.inc";
|
2020-12-01 10:22:17 +00:00
|
|
|
|
|
|
|
function are_files_identical(a, b)
|
|
|
|
{
|
|
|
|
@local f1, f2, x, y, diff;
|
2024-04-22 15:39:01 +00:00
|
|
|
|
2020-12-01 10:22:17 +00:00
|
|
|
f1 = sys::open(a, sys::O_RDONLY);
|
|
|
|
if (f1 <= -1)
|
|
|
|
{
|
|
|
|
printf ("ERROR: unable to open %s\n", a);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
f2 = sys::open(b, sys::O_RDONLY);
|
|
|
|
if (f2 <= -1)
|
|
|
|
{
|
|
|
|
sys::close (a);
|
|
|
|
printf ("ERROR: unable to open %s\n", b);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = 0;
|
|
|
|
while (sys::read(f1, x, 1) > 0)
|
|
|
|
{
|
2024-04-22 15:39:01 +00:00
|
|
|
if (sys::read(f2, y, 1) <= 0 || x !== y)
|
2020-12-01 10:22:17 +00:00
|
|
|
{
|
|
|
|
diff = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sys::read(f2, y, 1) > 0) diff = 1;
|
|
|
|
|
|
|
|
sys::close (f2);
|
|
|
|
sys::close (f1);
|
|
|
|
return !diff;
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:10:39 +00:00
|
|
|
function run_test (x, more_opts, in_name, set_out_name, out_name)
|
2020-12-01 10:22:17 +00:00
|
|
|
{
|
|
|
|
@local cmd, inf, expf, outf, same;
|
|
|
|
|
|
|
|
if (hawk::isnil(in_name)) in_name = x;
|
|
|
|
if (hawk::isnil(out_name)) out_name = x;
|
|
|
|
|
|
|
|
inf = sprintf("%s/%s.in", TDIR, in_name);
|
|
|
|
expf = sprintf("%s/%s.out", TDIR, out_name);
|
|
|
|
outf = sprintf("/tmp/%s.%d.out", out_name, sys::getpid());
|
|
|
|
##print TDIR, inf, expf, outf;
|
|
|
|
|
2022-04-09 06:10:39 +00:00
|
|
|
if (set_out_name)
|
2022-04-09 02:44:36 +00:00
|
|
|
{
|
2022-04-09 06:10:39 +00:00
|
|
|
cmd=sprintf("%s %s -vT_OUT_NAME=%s -f %s/%s.hawk --modlibdirs=%s %s", ARGV[0], more_opts, outf, TDIR, x, hawk::modlibdirs(), inf);
|
2022-04-09 02:44:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-09 06:10:39 +00:00
|
|
|
cmd=sprintf("%s %s -f %s/%s.hawk --modlibdirs=%s %s > %s", ARGV[0], more_opts, TDIR, x, hawk::modlibdirs(), inf, outf);
|
2024-04-22 15:39:01 +00:00
|
|
|
}
|
2020-12-01 10:22:17 +00:00
|
|
|
##print cmd;
|
|
|
|
system (cmd);
|
2024-04-22 15:39:01 +00:00
|
|
|
|
2020-12-01 10:22:17 +00:00
|
|
|
same = are_files_identical(expf, outf);
|
2024-04-22 15:39:01 +00:00
|
|
|
if (same <= 0)
|
2020-12-01 10:22:17 +00:00
|
|
|
{
|
|
|
|
## don't delete the output file for review.
|
2022-04-08 03:42:20 +00:00
|
|
|
tap_fail (sprintf("%s[%d] %s - %s and %s differ", @SCRIPTNAME, @SCRIPTLINE, x, expf, outf));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tap_ok (sprintf("%s[%d]", @SCRIPTNAME, @SCRIPTLINE));
|
2022-04-09 00:14:30 +00:00
|
|
|
sys::unlink (outf);
|
2020-12-01 10:22:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function main()
|
|
|
|
{
|
2022-04-09 06:10:39 +00:00
|
|
|
run_test ("journal-toc", "", @nil, 0, @nil);
|
|
|
|
run_test ("journal-toc", "-vHTML=1", "journal-toc", 0, "journal-toc-html");
|
|
|
|
run_test ("bibtex-to-html", "", "journal-toc", 1, "bibtex-to-html");
|
2022-04-09 02:44:36 +00:00
|
|
|
|
2022-04-08 03:42:20 +00:00
|
|
|
tap_end ();
|
2020-12-01 10:22:17 +00:00
|
|
|
}
|
|
|
|
|