| # Copyright 2021 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """ |
| Recipe to run unit tests for Starlark. |
| """ |
| |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/git", |
| "fuchsia/git_checkout", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = { |
| "repo": Property(kind=str, help="Salt repository to checkout."), |
| } |
| |
| TEST_SUFFIX = "_test.star" |
| |
| |
| def RunSteps(api, repo): |
| git_path, revision = api.git_checkout(repo) |
| |
| # Get a short revision, image names must be < 64 characters |
| with api.context(cwd=git_path): |
| revision = api.git( |
| "git rev-parse", |
| "rev-parse", |
| "--short", |
| revision, |
| stdout=api.raw_io.output_text(), |
| ).stdout.rstrip() |
| |
| test_paths = api.file.glob_paths( |
| "find starlark unit tests", git_path, "**/*" + TEST_SUFFIX |
| ) |
| for test_path in test_paths: |
| test_name = api.path.basename(test_path) |
| api.step(test_name, [test_path]) |
| |
| |
| def GenTests(api): |
| repo = "https://fuchsia.googlesource.com/infra/salt" |
| yield ( |
| api.buildbucket_util.test("success", git_repo=repo) |
| + api.properties(repo=repo) |
| + api.step_data( |
| "find starlark unit tests", |
| api.file.glob_paths( |
| [ |
| "foo_test.star", |
| "bar/baz_test.star", |
| ] |
| ), |
| ) |
| + api.step_data( |
| "foo_test.star", |
| retcode=0, |
| ) |
| + api.step_data( |
| "baz_test.star", |
| retcode=0, |
| ) |
| ) |
| |
| yield ( |
| api.buildbucket_util.test("failure", status="failure", git_repo=repo) |
| + api.properties(repo=repo) |
| + api.step_data( |
| "find starlark unit tests", |
| api.file.glob_paths( |
| [ |
| "bar/baz_test.star", |
| ] |
| ), |
| ) |
| + api.step_data( |
| "baz_test.star", |
| retcode=1, |
| ) |
| ) |