| 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 | |
| 33 try: | |
| 34 api.step('goodbye', ['echo', 'goodbye']) | |
| 35 # Modifying step_result now would raise an AssertionError. | |
| 36 except api.step.StepFailure: | |
| 37 # Raising anything besides StepFailure causes the build to go purple. | |
| 38 raise ValueError('goodbye must exit 0!') | |
| 39 | |
| 40 # Aggregate failures from tests! | |
| 41 try: | |
| 42 with recipe_api.defer_results(): | |
| 43 api.step('testa', ['echo', 'testa']) | |
| 44 api.step('testb', ['echo', 'testb']) | |
| 45 except recipe_api.AggregatedStepFailure as f: | |
| 46 raise api.step.StepFailure("You can catch step failures.") | |
| 47 | |
| 48 # Some steps are needed from an infrastructure point of view. If these | |
| 49 # steps fail, the build stops, but doesn't get turned red because it's | |
| 50 # not the developers' fault. | |
| 51 try: | |
| 52 api.step('cleanup', ['echo', 'cleaning', 'up', 'build'], infra_step=True) | |
| 53 except api.step.InfraFailure as f: | |
| 54 assert f.result.presentation.status == api.step.EXCEPTION | |
| 55 | |
| 56 # Run a step through a made-up wrapper program. | |
| 57 api.step('application', ['echo', 'main', 'application'], | |
| 58 wrapper=['python', 'test-wrapper.py', '-v', '--']) | |
| 59 | |
| 60 if api.properties.get('access_invalid_data'): | |
| 61 result = api.step('no-op', ['echo', 'I', 'do', 'nothing']) | |
| 62 # Trying to access non-existent attributes on the result should raise. | |
| 63 _ = result.json.output | |
| 64 | |
| 65 # You can also raise a warning, which will act like a step failure, but | |
| 66 # will turn the build yellow, and stop the build. | |
| 67 raise api.step.StepWarning("Warning, robots approaching!") | |
| 68 | |
| 69 | |
| 70 def GenTests(api): | |
| 71 yield ( | |
| 72 api.test('basic') + | |
| 73 api.step_data('anything is cool', retcode=3) | |
| 74 ) | |
| 75 | |
| 76 # If you don't have the expect_exception in this test, you will get something | |
| 77 # like this output. | |
| 78 # ====================================================================== | |
| 79 # ERROR: step:example.exceptional (..../exceptional.json) | |
| 80 # ---------------------------------------------------------------------- | |
| 81 # Traceback (most recent call last): | |
| 82 # <full stack trace ommitted> | |
| 83 # File "annotated_run.py", line 537, in run | |
| 84 # retcode = steps_function(api) | |
| 85 # File "recipe_modules/step/example.py", line 39, in RunSteps | |
| 86 # raise ValueError('goodbye must exit 0!') | |
| 87 # ValueError: goodbye must exit 0! | |
| 88 | |
| 89 yield ( | |
| 90 api.test('exceptional') + | |
| 91 api.step_data('goodbye (2)', retcode=1) + | |
| 92 api.expect_exception('ValueError') | |
| 93 ) | |
| 94 | |
| 95 yield ( | |
| 96 api.test('defer_results') + | |
| 97 api.step_data('testa', retcode=1) | |
| 98 ) | |
| 99 | |
| 100 yield ( | |
| 101 api.test('invalid_access') + | |
| 102 api.properties(access_invalid_data=True) + | |
| 103 api.expect_exception('StepDataAttributeError') | |
| 104 ) | |
| 105 | |
| 106 yield ( | |
| 107 api.test('infra_failure') + | |
| 108 api.properties(raise_infra_failure=True) + | |
| 109 api.step_data('cleanup', retcode=1) | |
| 110 ) | |
| OLD | NEW |