source: git/Singular/LIB/tst.lib @ 835e0e

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