source: git/Singular/LIB/tst.lib @ ac6554

spielwiese
Last change on this file since ac6554 was ac6554, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* corrected return statements (thanks, Christian) git-svn-id: file:///usr/local/Singular/svn/trunk@1799 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
Line 
1// $Id: tst.lib,v 1.6 1998-05-15 16:18:19 obachman Exp $
2//(obachman, last modified 2/13/98)
3///////////////////////////////////////////////////////////////////////////////
4
5version="$Id: tst.lib,v 1.6 1998-05-15 16:18:19 obachman 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)
19"USAGE:    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
41"USAGE:    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 usage with the keyword \"memory\"
51EXAMPLE:  example tst_ignore; shows examples
52"
53{
54  string s;
55  string keyword = "";
56  link outlink = "";
57
58  // Check # of args
59  if (size(#) < 1 || size(#) > 3)
60  {
61    "Error tst_ignore: Wrong number of arguments";
62    "Usage: tst_ignore (any,[keyword], [link]);";
63    return();
64  }
65
66  // Get Args
67  s = string(#[1]);
68  if (size(#) == 3)
69  {
70    keyword = #[2];
71    outlink = #[3];
72  }
73  if (size(#) == 2)
74  {
75    if (typeof(#[2]) == "string")
76    {
77      keyword = #[2];
78    }
79    else
80    {
81      outlink = #[2];
82    }
83  }
84
85  // check args
86  if (typeof(keyword) != "string")
87  {
88    "Error tst_ignore: Keyword must be a string";
89    "Usage: tst_ignore (any,[keyword], [link]);";
90    return();
91  }
92  if (keyword == "time" || keyword == "memory")
93  {
94    keyword = keyword + ": ";
95  }
96  else
97  {
98    if (keyword != "")
99    {
100      "Warning tst_ignore: keyword should be \"time\" or \"memory\"";
101    }
102  }
103
104  if (status(outlink, "open", "no"))
105  {
106    open(outlink);
107  }
108  if (status(outlink, "write", "not ready"))
109  {
110    "Error tst_ignore: Can not write to link";
111    outlink;
112    "Usage: tst_ignore (any,[keyword], [link]);";
113    return();
114  }
115
116  // ready -- do the actual work
117  write(outlink, "// ignore: " + keyword + s);
118}
119example
120{
121  "EXAMPLE";
122  "System independent data can safely be output in tst files;";
123  "However, system dependent data like dates, or pathnames, should be output";
124  "using the command tst_ignore(...), like";
125  echo = 2;
126  tst_ignore(tst_system("date"));
127  int t1 = timer;
128  tst_ignore(t1, "time");
129  tst_ignore(memory(1), "memory");
130}
131
132proc tst_init
133"USAGE:   tst_init()
134RETURN:  none; writes some identification data to stdout;
135         should be called as first routine in a tst file
136EXAMPLE: example tst_init; shows example
137"
138{
139  tst_ignore("USER    : " + system("getenv", "USER"));
140  tst_ignore("HOSTNAME: " + system("getenv", "HOST"));
141  tst_ignore("uname -a: " + tst_system("uname -a"));
142  tst_ignore("date    : " + tst_system("date"));
143  tst_ignore("version : " + string(system("version")));
144}
145example
146{
147  "EXAMPLE";  echo = 2;
148  tst_init();
149}
150
151
152
Note: See TracBrowser for help on using the repository browser.