OLD | NEW |
| (Empty) |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 DEPS = [ | |
6 'path', | |
7 'raw_io', | |
8 'step', | |
9 ] | |
10 | |
11 | |
12 def RunSteps(api): | |
13 # Read command's stdout and stderr. | |
14 step_result = api.step('echo', ['echo', 'Hello World'], | |
15 stdout=api.raw_io.output(), | |
16 stderr=api.raw_io.output()) | |
17 assert step_result.stdout == 'Hello World\n' | |
18 assert step_result.stderr == '' | |
19 | |
20 # Pass stuff to command's stdin, read it from stdout. | |
21 step_result = api.step('cat', ['cat'], | |
22 stdin=api.raw_io.input(data='hello'), | |
23 stdout=api.raw_io.output('out')) | |
24 assert step_result.stdout == 'hello' | |
25 | |
26 # Example of auto-mocking stdout. '\n' appended to mock 'echo' behavior. | |
27 step_result = api.step('automock', ['echo', 'huh'], | |
28 stdout=api.raw_io.output('out'), | |
29 step_test_data=( | |
30 lambda: api.raw_io.test_api.stream_output('huh\n'))) | |
31 assert step_result.stdout == 'huh\n' | |
32 | |
33 # Example of auto-mocking stdout + stderr. | |
34 step_result = api.step( | |
35 'automock (fail)', ['bash', '-c', 'echo blah && echo fail 1>&2'], | |
36 stdout=api.raw_io.output('out'), | |
37 stderr=api.raw_io.output('err'), | |
38 step_test_data=( | |
39 lambda: ( | |
40 api.raw_io.test_api.stream_output('blah\n') + | |
41 api.raw_io.test_api.stream_output('fail\n', 'stderr') | |
42 )) | |
43 ) | |
44 assert step_result.stdout == 'blah\n' | |
45 assert step_result.stderr == 'fail\n' | |
46 | |
47 # leak_to coverage. | |
48 step_result = api.step( | |
49 'leak stdout', ['echo', 'leaking'], | |
50 stdout=api.raw_io.output(leak_to=api.path['slave_build'].join('out.txt')), | |
51 step_test_data=( | |
52 lambda: api.raw_io.test_api.stream_output('leaking\n'))) | |
53 assert step_result.stdout == 'leaking\n' | |
54 | |
55 api.step('list temp dir', ['ls', api.raw_io.output_dir()]) | |
56 api.step('leak dir', ['ls', api.raw_io.output_dir( | |
57 leak_to=api.path['slave_build'].join('out'))]) | |
58 | |
59 | |
60 def GenTests(api): | |
61 yield (api.test('basic') + | |
62 api.step_data('echo', | |
63 stdout=api.raw_io.output('Hello World\n'), | |
64 stderr=api.raw_io.output('')) + | |
65 api.step_data('cat', | |
66 stdout=api.raw_io.output('hello'))) | |
OLD | NEW |