1 | // $Id: tst.lib,v 1.3 1998-04-03 22:47:15 krueger Exp $ |
---|
2 | //(obachman, last modified 2/13/98) |
---|
3 | /////////////////////////////////////////////////////////////////////////////// |
---|
4 | |
---|
5 | version="$Id: tst.lib,v 1.3 1998-04-03 22:47:15 krueger Exp $"; |
---|
6 | info=" |
---|
7 | LIBRARY: 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 | |
---|
18 | proc tst_system(string s) |
---|
19 | USAGE: tst_system(s); s string |
---|
20 | RETURN: string which is stdout and stderr of system("sh", s) |
---|
21 | EXAMPLE: 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 | } |
---|
32 | example |
---|
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 | |
---|
40 | proc 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 |
---|
45 | RETURN: 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" |
---|
51 | EXAMPLE: 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 | } |
---|
118 | example |
---|
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 | |
---|
131 | proc tst_init |
---|
132 | USAGE: tst_init() |
---|
133 | RETURN: none; writes some identification data to stdout; |
---|
134 | should be called as first routine in a tst file |
---|
135 | EXAMPLE: 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 | } |
---|
143 | example |
---|
144 | { |
---|
145 | "EXAMPLE"; echo = 2; |
---|
146 | tst_init(); |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | |
---|