// $Id: tst.lib,v 1.4 1998-05-05 11:55:40 krueger Exp $ //(obachman, last modified 2/13/98) /////////////////////////////////////////////////////////////////////////////// version="$Id: tst.lib,v 1.4 1998-05-05 11:55:40 krueger Exp $"; info=" LIBRARY: tst.lib PROCEDURES FOR RUNNING AUTOMATIC TST TESTS tst_system(s) returns string which is stdout of system(\"sh\", s) tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout), prepending prefix \"// ignore:\" tst_init() writes some identification data to stdout with tst_ignore "; /////////////////////////////////////////////////////////////////////////////// proc tst_system(string s) "USAGE: tst_system(s); s string RETURN: string which is stdout \x and stderr of system(\"sh\", s) EXAMPLE: example tst_system; shows examples " { string tmpfile = "/tmp/tst_" + string(system("pid")); int errno; s = s + " 1>" + tmpfile + " 2>&1"; errno = system("sh", s); s = read(tmpfile); errno = system("sh", "rm " + tmpfile); return (s); } example { "EXAMPLE"; echo = 2; string s = tst_system("echo This is is an example of tst_system"); "The following is what the system call wrote to stdout: " + s; } proc tst_ignore "USAGE: tst_ignore(any,[keyword], [link]) any -- valid argument to string() keyword -- one of \"time\" or \"memory\" link -- a link which can be written to RETURN: none; writes string(any) to link (or stdout, if no link given), prepending prefix \"// ignore:\", or \"// ignore: time:\", \"//ignore: memory:\" if called with the respective keywords; should be used in tst files to output system dependent data (like date, pathnames) { and timings With the keyword \"time\", resp. memory usage with the keyword \"memory\" EXAMPLE: example tst_ignore; shows examples " { string s; string keyword = ""; link outlink = ""; // Check # of args if (size(#) < 1 || size(#) > 3) { "Error tst_ignore: Wrong number of arguments"; "Usage: tst_ignore (any,[keyword], [link]);"; return; } // Get Args s = string(#[1]); if (size(#) == 3) { keyword = #[2]; outlink = #[3]; } if (size(#) == 2) { if (typeof(#[2]) == "string") { keyword = #[2]; } else { outlink = #[2]; } } // check args if (typeof(keyword) != "string") { "Error tst_ignore: Keyword must be a string"; "Usage: tst_ignore (any,[keyword], [link]);"; return; } if (keyword == "time" || keyword == "memory") { keyword = keyword + ": "; } else { if (keyword != "") { "Warning tst_ignore: keyword should be \"time\" or \"memory\""; } } if (status(outlink, "open", "no")) { open(outlink); } if (status(outlink, "write", "not ready")) { "Error tst_ignore: Can not write to link"; outlink; "Usage: tst_ignore (any,[keyword], [link]);"; return; } // ready -- do the actual work write(outlink, "// ignore: " + keyword + s); } example { "EXAMPLE"; "System independent data can safely be output in tst files;"; "However, system dependent data like dates, or pathnames, should be output"; "using the command tst_ignore(...), like"; echo = 2; tst_ignore(tst_system("date")); int t1 = timer; tst_ignore(t1, "time"); tst_ignore(memory(1), "memory"); } proc tst_init "USAGE: tst_init() RETURN: none; writes some identification data to stdout; should be called as first routine in a tst file EXAMPLE: example tst_init; shows example " { tst_ignore("USER : " + system("getenv", "USER")); tst_ignore("HOSTNAME: " + system("getenv", "HOST")); tst_ignore("uname -a: " + tst_system("uname -a")); tst_ignore("date : " + tst_system("date")); tst_ignore("version : " + string(system("version"))); } example { "EXAMPLE"; echo = 2; tst_init(); }