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

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