## template-hostthread-unit-test.pkg
#
# Unit/regression test functionality for
#
#
src/lib/std/src/hostthread/template-hostthread.pkg#
# (The template_hostthread server is a template for creating
# new hostthread servers by clone-and-mutate.)
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkgstipulate
# package hth = hostthread; # hostthread is from
src/lib/std/src/hostthread.pkg package tp = template_hostthread; # template_hostthread is from
src/lib/std/src/hostthread/template-hostthread.pkg #
sleep = makelib::scripting_globals::sleep;
herein
package template_hostthread_unit_test {
#
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg
name = "src/lib/std/src/hostthread/template-hostthread-unit-test.pkg";
fun verify_basic__is_running__operation ()
=
{ # Pretty minimal test: :-)
#
assert( tp::is_running () );
};
fun verify_basic__echo__operation ()
=
{ echoed_text = REF "";
#
tp::echo { what => "foo", reply => (\\ what = (echoed_text := what)) };
#
sleep 0.01;
#
assert( *echoed_text == "foo" );
};
fun verify_basic__stop__operation ()
=
{ tp::stop { who => "template-hostthread-unit-test", reply => (\\ _ = ()) };
#
sleep 0.01;
#
assert (not (tp::is_running ()));
#
tp::start "template-hostthread-unit-test";
sleep 0.01;
#
assert( tp::is_running () );
};
fun run ()
=
{ printf "\nDoing %s:\n" name;
#
tp::start "template-hostthread-unit-test"; # This will be a no-op if it is already running.
#
verify_basic__is_running__operation ();
verify_basic__echo__operation ();
verify_basic__stop__operation ();
#
summarize_unit_tests name;
};
};
end;