OLD | NEW |
| (Empty) |
1 # Copyright 2013 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 'properties', | |
7 'step', | |
8 ] | |
9 | |
10 from recipe_engine import recipe_api | |
11 | |
12 def RunSteps(api): | |
13 # TODO(martinis) change this | |
14 # The api.step object is directly callable. | |
15 api.step('hello', ['echo', 'Hello World']) | |
16 api.step('hello', ['echo', 'Why hello, there.']) | |
17 | |
18 # You can also manipulate various aspects of the step, such as env. | |
19 # These are passed straight through to subprocess.Popen. | |
20 # Also, abusing bash -c in this way is a TERRIBLE IDEA DON'T DO IT. | |
21 api.step('goodbye', ['bash', '-c', 'echo Good bye, $friend.'], | |
22 env={'friend': 'Darth Vader'}) | |
23 | |
24 # Finally, you can make your step accept any return code | |
25 api.step('anything is cool', ['bash', '-c', 'exit 3'], | |
26 ok_ret='any') | |
27 | |
28 # We can manipulate the step presentation arbitrarily until we run | |
29 # the next step. | |
30 step_result = api.step('hello', ['echo', 'hello']) | |
31 step_result.presentation.status = api.step.EXCEPTION | |
32 step_result.presentation.logs['the reason'] = ['The reason\nit failed'] | |
33 | |
34 # Without a command, a step can be used to present some data from the recipe. | |
35 step_result = api.step('Just print stuff', cmd=None) | |
36 step_result.presentation.logs['more'] = ['More stuff'] | |
37 | |
38 try: | |
39 api.step('goodbye', ['echo', 'goodbye']) | |
40 # Modifying step_result now would raise an AssertionError. | |
41 except api.step.StepFailure: | |
42 # Raising anything besides StepFailure causes the build to go purple. | |
43 raise ValueError('goodbye must exit 0!') | |
44 | |
45 # Aggregate failures from tests! | |
46 try: | |
47 with recipe_api.defer_results(): | |
48 api.step('testa', ['echo', 'testa']) | |
49 api.step('testb', ['echo', 'testb']) | |
50 except recipe_api.AggregatedStepFailure as f: | |
51 raise api.step.StepFailure("You can catch step failures.") | |
52 | |
53 # Some steps are needed from an infrastructure point of view. If these | |
54 # steps fail, the build stops, but doesn't get turned red because it's | |
55 # not the developers' fault. | |
56 try: | |
57 api.step('cleanup', ['echo', 'cleaning', 'up', 'build'], infra_step=True) | |
58 except api.step.InfraFailure as f: | |
59 assert f.result.presentation.status == api.step.EXCEPTION | |
60 | |
61 # Run a step through a made-up wrapper program. | |
62 api.step('application', ['echo', 'main', 'application'], | |
63 wrapper=['python', 'test-wrapper.py', '-v', '--']) | |
64 | |
65 if api.properties.get('access_invalid_data'): | |
66 result = api.step('no-op', ['echo', 'I', 'do', 'nothing']) | |
67 # Trying to access non-existent attributes on the result should raise. | |
68 _ = result.json.output | |
69 | |
70 # You can also raise a warning, which will act like a step failure, but | |
71 # will turn the build yellow, and stop the build. | |
72 raise api.step.StepWarning("Warning, robots approaching!") | |
73 | |
74 | |
75 def GenTests(api): | |
76 yield ( | |
77 api.test('basic') + | |
78 api.step_data('anything is cool', retcode=3) | |
79 ) | |
80 | |
81 # If you don't have the expect_exception in this test, you will get something | |
82 # like this output. | |
83 # ====================================================================== | |
84 # ERROR: step:example.exceptional (..../exceptional.json) | |
85 # ---------------------------------------------------------------------- | |
86 # Traceback (most recent call last): | |
87 # <full stack trace ommitted> | |
88 # File "annotated_run.py", line 537, in run | |
89 # retcode = steps_function(api) | |
90 # File "recipe_modules/step/example.py", line 39, in RunSteps | |
91 # raise ValueError('goodbye must exit 0!') | |
92 # ValueError: goodbye must exit 0! | |
93 | |
94 yield ( | |
95 api.test('exceptional') + | |
96 api.step_data('goodbye (2)', retcode=1) + | |
97 api.expect_exception('ValueError') | |
98 ) | |
99 | |
100 yield ( | |
101 api.test('defer_results') + | |
102 api.step_data('testa', retcode=1) | |
103 ) | |
104 | |
105 yield ( | |
106 api.test('invalid_access') + | |
107 api.properties(access_invalid_data=True) + | |
108 api.expect_exception('StepDataAttributeError') | |
109 ) | |
110 | |
111 yield ( | |
112 api.test('infra_failure') + | |
113 api.properties(raise_infra_failure=True) + | |
114 api.step_data('cleanup', retcode=1) | |
115 ) | |
OLD | NEW |