


# scripting-unit-test.pkg
# Compiled by:
# src/lib/test/unit-tests.lib# Run by:
# src/lib/test/all-unit-tests.pkg# Unit tests for:
# Basic scripting functionality.
stipulate
package psx = posix_1003_1b; # posix_1003_1b is from src/lib/std/src/posix-1003.1b/posix-1003-1b.pkgherein
package scripting_unit_test {
#
include unit_test; # unit_test is from src/lib/src/unit-test.pkg bash = spawn::bash;
back__ticks = spawn::bash;
name = "src/lib/src/scripting-unit-test.pkg tests";
script_name = "test~";
# XXX BUGGO FIXME We in fact wind up invoking
# the installed image /usr/bin/mythryld
# -- it would be much better if we invoked
# the local bin/mythryld so that we could
# test before installing -- and so that we
# don't get confused thinking we're testing
# the latest compile when we're not.
#
fun create_script script_text
=
{ cwd = winix::file::current_directory ();
fd = file::open_for_write script_name;
file::write (fd, "#!" + cwd + "/bin/mythryl\n");
file::write (fd, script_text + "\n");
file::close_output fd;
psx::chmod (script_name, psx::s::irwxu);
};
infix val --> ;
fun a --> b
=
(a, b);
# Creating and running a script is relatively slow,
# so where we have a choice, we put tests in
# src/lib/src/eval-unit-test.pkg # instead:
#
internal_script_tests
=
[ "printf \"%d\" (2+2);" --> "4",
"printf \"%s\" (\"abc\" + \"def\");" --> "abcdef"
];
external_script_tests
=
[ "try/run-subprocess" --> "Read from subprocess: 'xyzzy'"
];
fun run_an_internal_script_test (question, answer)
=
{ create_script question;
# result = `./test~`; printf "src/lib/src/scripting-unit-test.pkg: question s='%s' proper answer s='%s' actual answer s='%s' script_name s=%s'\n" question answer result script_name;
assert (`./test~` == answer);
winix::file::remove_file script_name;
};
fun run_an_external_script_test (question, answer)
=
{
# print ("src/lib/src/scripting-unit-test.pkg: run_an_external_script_test: '" + question + "' -> '" + (bash question) + "'\n");
assert (string::chomp (bash question) == answer);
};
fun run ()
=
{
printf "\nDoing %s:\n" name;
apply run_an_internal_script_test internal_script_tests;
apply run_an_external_script_test external_script_tests;
summarize_unit_tests name;
};
};
end;
## Code by Jeff Prothero: Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


