| # Copyright 2020 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. |
| |
| """A recipe for testing Go code in a Fuchsia checkout using standard Go tooling. |
| |
| We use `go test` instead of the Fuchsia build/test system to ensure that Go |
| code in Fuchsia is compatible with standard Go tooling. Maintaining this |
| compatibility has several advantages: |
| - Enables useful text editor integration with Go tools (autocomplete, |
| intellisense, linting, etc.). |
| - Using `go test` is much faster than doing a full fx build and test cycle, |
| significantly speeding up iteration. |
| - Makes it easier for new contributors familiar with standard Go tooling to |
| get up to speed writing Go in Fuchsia. |
| """ |
| |
| from PB.recipes.fuchsia.fuchsia.go_tests import InputProperties |
| |
| DEPS = [ |
| "fuchsia/checkout", |
| "recipe_engine/context", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| # Go files that are marked as NOT satisfying this build constraint will be |
| # excluded from testing, since some Fuchsia Go code is incompatible with the |
| # native Go toolchain. See https://golang.org/cmd/go/#hdr-Build_constraints for |
| # more info on build tags. |
| FILTER_TAG = "build_with_native_toolchain" |
| |
| |
| def RunSteps(api, props): |
| checkout = api.checkout.fuchsia_with_options( |
| manifest=props.manifest, |
| remote=props.remote, |
| ) |
| |
| platform = "%s-%s" % ( |
| api.platform.name.replace("win", "windows"), |
| {"intel": "x64", "arm": "arm64"}[api.platform.arch], |
| ) |
| go_exe = checkout.root_dir.joinpath( |
| "prebuilt", "third_party", "go", platform, "bin", "go" |
| ) |
| api.path.mock_add_paths(go_exe) |
| if not api.path.exists(go_exe): # pragma: no cover |
| raise api.step.InfraFailure( |
| f"go executable does not exist at expected path: {go_exe}" |
| ) |
| |
| common_args = ["-mod", "readonly", "-tags", FILTER_TAG, "./..."] |
| |
| with api.context(cwd=checkout.root_dir): |
| # Build separately from testing so that build failures show up as |
| # failures in the "go build" step rather than "go test". |
| api.step("go build", [go_exe, "build"] + common_args) |
| |
| # Use -short for now to help with getting the builder green for |
| # fxbug.dev/58804. The tests requiring a fx build should call |
| # t.Skip() when testing.Short() is true. |
| test_cmd = [go_exe, "test", "-v", "-short"] + common_args |
| api.step("go test -short", test_cmd) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.test("basic") |
| + api.properties( |
| manifest="flower", remote="https://fuchsia.googlesource.com/integration" |
| ) |
| ) |