source: git/Singular/LIB/tst.lib @ 5480da

spielwiese
Last change on this file since 5480da was 5480da, checked in by Kai Krüger <krueger@…>, 26 years ago
Added new help for libraries git-svn-id: file:///usr/local/Singular/svn/trunk@1318 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
Line 
1// $Id: tst.lib,v 1.3 1998-04-03 22:47:15 krueger Exp $
2//(obachman, last modified 2/13/98)
3///////////////////////////////////////////////////////////////////////////////
4
5version="$Id: tst.lib,v 1.3 1998-04-03 22:47:15 krueger Exp $";
6info="
7LIBRARY:  tst.lib      PROCEDURES FOR RUNNING AUTOMATIC TST TESTS
8
9 tst_system(s)          returns string which is stdout of system(\"sh\", s)
10 tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout),
11                                   prepending prefix \"// ignore:\"
12 tst_init()             writes some identification data to stdout
13                        with tst_ignore
14";
15
16///////////////////////////////////////////////////////////////////////////////
17
18proc tst_system(string s)
19USAGE:    tst_system(s); s string
20RETURN:   string which is stdout and stderr of system("sh", s)
21EXAMPLE:  example tst_system; shows examples
22{
23  string tmpfile = "/tmp/tst_" + string(system("pid"));
24  int errno;
25 
26  s = s + " 1>" + tmpfile + " 2>&1";
27  errno = system("sh", s);
28  s = read(tmpfile);
29  errno = system("sh", "rm " + tmpfile);
30  return (s);
31}
32example
33{
34  "EXAMPLE"; echo = 2;
35  string s = tst_system("echo This is is an example of tst_system");
36  "The following is what the system call wrote to stdout: " + s;
37}
38
39 
40proc tst_ignore
41USAGE:    tst_ignore(any,[keyword], [link])
42            any     -- valid argument to string()
43            keyword -- one of "time" or "memory"
44            link    -- a link which can be written to
45RETURN:   none; writes string(any) to link (or stdout, if no link given),
46          prepending prefix "// ignore:", or "// ignore: time:",
47          "//ignore: memory:"  if called with the respective keywords;
48          should be used in tst files to output system dependent data
49          (like date, pathnames) and timings With the keyword "time",
50          resp. memory usgae with the keyword "memory"
51EXAMPLE:  example tst_ignore; shows examples
52{
53  string s;
54  string keyword = "";
55  link outlink = "";
56 
57  // Check # of args
58  if (size(#) < 1 || size(#) > 3)
59  {
60    "Error tst_ignore: Wrong number of arguments";
61    "Usage: tst_ignore (any,[keyword], [link]);";
62    return;
63  }
64 
65  // Get Args
66  s = string(#[1]);
67  if (size(#) == 3)
68  {
69    keyword = #[2];
70    outlink = #[3];
71  }
72  if (size(#) == 2)
73  {
74    if (typeof(#[2]) == "string")
75    {
76      keyword = #[2];
77    }
78    else
79    {
80      outlink = #[2];
81    }
82  }
83 
84  // check args
85  if (typeof(keyword) != "string")
86  {
87    "Error tst_ignore: Keyword must be a string";
88    "Usage: tst_ignore (any,[keyword], [link]);";
89    return;
90  }
91  if (keyword == "time" || keyword == "memory")
92  {
93    keyword = keyword + ": ";
94  }
95  else
96  {
97    if (keyword != "")
98    {
99      "Warning tst_ignore: keyword should be \"time\" or \"memory\"";
100    }
101  }
102 
103  if (status(outlink, "open", "no"))
104  {
105    open(outlink);
106  }
107  if (status(outlink, "write", "not ready"))
108  {
109    "Error tst_ignore: Can not write to link";
110    outlink;
111    "Usage: tst_ignore (any,[keyword], [link]);";
112    return;
113  }
114 
115  // ready -- do the actual work
116  write(outlink, "// ignore: " + keyword + s);
117}
118example
119{
120  "EXAMPLE";   
121  "System independent data can safely be output in tst files;";
122  "However, system dependent data like dates, or pathnames, should be output";
123  "using the command tst_ignore(...), like";
124  echo = 2;
125  tst_ignore(tst_system("date"));
126  int t1 = timer;
127  tst_ignore(t1, "time");
128  tst_ignore(memory(1), "memory");
129}
130
131proc tst_init
132USAGE:   tst_init()
133RETURN:  none; writes some identification data to stdout;
134         should be called as first routine in a tst file
135EXAMPLE: example tst_init; shows example
136{
137  tst_ignore("USER    : " + system("getenv", "USER"));
138  tst_ignore("HOSTNAME: " + system("getenv", "HOST"));
139  tst_ignore("uname -a: " + tst_system("uname -a"));
140  tst_ignore("date    : " + tst_system("date"));
141  tst_ignore("version : " + string(system("version")));
142}
143example
144{
145  "EXAMPLE";  echo = 2;
146  tst_init();
147}
148
149
150 
Note: See TracBrowser for help on using the repository browser.