File: stest_tests.rb

package info (click to toggle)
genomethreader 1.7.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 46,528 kB
  • sloc: ansic: 90,168; ruby: 1,769; makefile: 548; sh: 112; perl: 105
file content (376 lines) | stat: -rwxr-xr-x 7,051 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

# Patrick Maass, 2006

if $0 == __FILE__
  require 'stest'
  at_exit do
    OnError do exit 1 end
  end
end

def run_g(str, opts = {})
  cmd = {}
  prefix = ""
  if $arguments["valgrind"] == "yes"
    prefix = "valgrind --leak-check=yes "
  end
  opts[:stdout] = "std_out"
  opts[:stderr] = "std_err"
  run(prefix + str, opts)
  if $arguments["valgrind"] == "yes"
    run %{grep "ERROR SUMMARY: 0 errors" std_out std_err}
  end
end

def run_stest(fn, str, args = [], opts = {})
  tfn = "#{fn}.rb"
  File.open(tfn, "w") do |f|
    f.print(str)
  end
  run "ruby #{$runpath}/stest.rb #{tfn} #{args.join(" ")}", opts
end

Description "Hello, World"
Keywords "basics--apply--run"
Test do
  run_g "echo huhu"
  run "echo hello"
end

Name "Hello, World 2 and a long ending"
Keywords "basics--retval"
Test do
  run("grep foo barbaz", :retval => 2)
end

Descr "Unavailable executable"
Keywords "basics--no-exec"
Test do
  run_stest "tt", %{
    Name "No such exe"
    Keywords "test--no-exe"
    Test do
      run "no-such-exe foo"
    end
  }, [], :retval => 1
  grep($last_stdout, /problem: exec failed/)
end

Name "Unavailable executables"
Keywords "basics--multi-no-exec"
Test do
  run_stest "tt", %{
    Name "No such exe"
    Keywords "test--no-exe"
    Test do
      run "no-such-exe foo"
      run "no-such-exe-either"
    end
    Name "No such exe2"
    Keywords "test--no-exe2"
    Test do
      run "some-other bar"
    end
  }, [], :retval => 1
  grep($last_stdout, /problem: exec failed/)
  grep($last_stdout, /2:.*: error/)
end

Name "Arguments"
Keywords "basics--run-arguments"
Test do
  run "echo *"
  run "echo ______"
  run("echo", :arguments => [ "*" ])
end

Name "Environment"
Keywords "basics--environment"
Test do
  run("sh -c 'echo LL $TATA'", :env => { "TATA" => "foo" })
end

Name "Test Input Files"
Keywords "basics--write-file"
Test do
  rundir = $runpath
  File.open("tt.rb", "w") do |f|
    f.puts %{
      require 'stest'
      Name "TestTest"
      Test do
        run "echo hello"
      end
    }
  end
  run "ruby -I#{rundir} tt.rb"
end

Name "Test Error Log"
Keywords "basics--error-log"
Test do
  run_stest "tt", %{
    Name "Foo"
    Test do
      failtest "and this is why"
    end
  }, [], :retval => 1
  grep("stest_tt/test1/stest_error", /^and this is why:$/)
end

Name "Numbered output files"
Keywords "basics--output-files"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "echo hello"
      run "echo huhu"
    end
  }
  run "test -r stest_tt/test1/stdout_1"
  run "test -r stest_tt/test1/stdout_2"
end

Name "Store commands"
Keywords "basics--store-commands"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "echo hello"
    end
  }
  File.open("stest_tt/test1/run_1") do |f|
    l = f.readlines
    if l[0].chomp != "$CMD_PREFIX echo hello"
      failtest "invalid command stored"
    end
  end
end

Name "Test without keywords"
Keywords "basics--without-keywords"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "echo"
    end
  }, [ "-keywords", "some" ]
  run "test ! -d stest_tt"
  run_stest "kk", %{
    Name "foo"
    Test do
      run "echo hello"
    end
  }, [ "-keywords", "not foo" ]
  run "test -r stest_kk/test1/run_1"
end

Name "Keyword Tokens"
Keywords "basics--keyword-parser"
Test do
  run_stest "tt", %{
    Name "foo"
    Keywords "x"
    Test do
      run "echo hello"
    end
    Name "bar"
    Keywords "notfoo foo"
    Test do
      run "echo huhu"
    end
  }, [ "-keywords", "notfoo" ]
  run "test ! -d stest_tt/test1"
  run "test -d stest_tt/test2"
end

Name "Test Selection"
Keywords "basics--selection"
Test do
  run_stest "tt", %{
    Name "s1"
    Test do
      run "echo foo"
    end
    Name "s2"
    Test do
      run "echo bar"
    end
    Name "s3"
    Test do
      run "echo baz"
    end
  }, %w{-select 2 3}
  grep("stest_tt/test2/stdout_1", "^bar$")
  grep("stest_tt/test3/stdout_1", "^baz$")
  run "test ! -d stest_tt/test1"
end

Name "Test Selection (name)"
Keywords "basics--name-selection"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "echo hello"
    end
    Name "bar"
    Test do
      run "echo huhu"
    end
  }, [ "-name", "b.r" ]
  grep("stest_tt/test2/stdout_1", /^huhu$/)
  run "test ! -d stest_tt/test1"
end

Name "Inverse grep"
Keywords "utils--inverse-grep"
Test do
  run_stest "tt", %{
    Name "gt"
    Test do
      run "echo foo"
      grep($last_stdout, /foo/)
      grep($last_stdout, /bar/, true)
    end
  }
end

Name "Grep string"
Keywords "utils--string-grep"
Test do
  run_stest "tt", %{
    Name "sg"
    Test do
      run "echo foo"
      grep($last_stdout, ".")
    end
  }
end

Name "Multi-file grep"
Keywords "utils--multi-grep"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "echo foo"
      grep([$last_stdout, $last_stderr], /^foo/)
      run "echo bar", :stdout => "s", :stderr => "e"
      grep(%w{e s}, /^bar/)
    end
  }
  run_stest "ft", %{
    Name "will-fail"
    Test do
      run "echo hello"
      grep([$last_stdout, $last_stderr], /nowhere/)
    end
  }, [], :retval => 1
  grep($last_stdout, /: failed/)
end

Name "Return Codes"
Keywords "basics--return-codes"
Test do
  run_stest "tt", %{
    Name "sg"
    Test do
      # will fail:
      run "echo foo", :retval => 1
    end
  }, [], :retval => 1
end

Name "Command Line Arguments"
Keywords "basics--command-line"
Test do
  run_stest "tt", %{
    Name "pa"
    Test do
      run "echo #\{$arguments["hello"]\}"
      run "echo #\{$arguments["flag"]\}"
    end
  }, %w{-hello hello world -flag}
  grep("stest_tt/test1/stdout_1", /^hello world$/)
  grep("stest_tt/test1/stdout_2", /^yes$/)
end

Name "Write-File"
Keywords "utils--write-file"
Test do
  run_stest "tt", %{
    Name "wf"
    Test do
      write_file "foo", %{
        from column 0
          indent
        end block
      }
    end
  }
  File.open("stest_tt/test1/foo", "r") do |f|
    l = f.readlines
    failtest "bad offset" if l[0] != "from column 0\n"
    failtest "line 1 != '  indent'" if l[1] != "  indent\n"
    failtest "line 2 != 'end block'" if l[2] != "end block\n"
    failtest "too many lines" if l.size != 3
  end
end

Name "Max Time"
Keywords "basics--max-time"
Test do
  run_stest "tt", %{
    Name "foo"
    Test do
      run "sleep 3", :maxtime => 1
    end
  }, [], :retval => 1
  grep $last_stdout, /did not finish on time/
end

Name "Range Selection"
Keywords "selection--ranges"
Test do
  run_stest "tt", %{
    Name "foo"
    Test {}
    Name "bar"
    Test {}
    Name "baz"
    Test {}
  }, %w{-select 2..3}
  grep $last_stdout, "bar"
  grep $last_stdout, "baz"
  grep $last_stdout, "foo", true
end

Name "Require/Provide"
Keywords "basics--require"
Test do
  run_stest "tt", %{
    Test.have_features do |str|
      if str =~ /^x/
        true
      else
        [ false, "skipped" ]
      end
    end
    Name "foo"
    Requires "x y v"
    Test do
      run "echo"
    end
    Name "bar"
    Requires "k y v"
    Test do
      run "echo"
    end
  }
  grep $last_stdout, /1:.*: ok/
end