| #!/bin/bash |
| # Copyright 2026 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. |
| |
| ### Test "lint" script. |
| |
| readonly TESTDATA="data/fx_format_code_test" |
| |
| BT_FILE_DEPS=( |
| "scripts/fx" |
| "tools/devshell/lint" |
| "tools/devshell/lib/fx-cmd-locator.sh" |
| "tools/devshell/lib/fx-optional-features.sh" |
| "tools/devshell/lib/generate-ssh-config.sh" |
| "tools/devshell/lib/vars.sh" |
| "tools/devshell/lib/is_invoked_by_agent.sh" |
| "tools/devshell/lib/agents.txt" |
| "tools/devshell/tests/subcommands/${TESTDATA}/cml.cml" |
| "tools/devshell/tests/subcommands/${TESTDATA}/cplusplus.cc" |
| "tools/devshell/tests/subcommands/${TESTDATA}/rust.rs" |
| "tools/devshell/tests/subcommands/${TESTDATA}/fidl.test.fidl" |
| "tools/devshell/tests/subcommands/${TESTDATA}/gidl.gidl" |
| "tools/devshell/tests/subcommands/${TESTDATA}/gn.gn" |
| "tools/devshell/tests/subcommands/${TESTDATA}/gn.gni" |
| "tools/devshell/tests/subcommands/${TESTDATA}/json5.json5" |
| "tools/devshell/tests/subcommands/${TESTDATA}/python3.py" |
| ) |
| |
| MOCK_CLANG_DIR="prebuilt/third_party/clang/test" |
| MOCK_SHAC="prebuilt/third_party/shac/shac" |
| MOCK_PYTHON3_DIR="prebuilt/third_party/python3/test" |
| BT_MOCKED_TOOLS=( |
| "scripts/fuchsia-vendored-python" |
| "tools/devshell/list-build-artifacts" |
| "tools/devshell/lib/platform.sh" |
| "${MOCK_CLANG_DIR}/bin/clang-tidy" |
| "${MOCK_CLANG_DIR}/bin/run-clang-tidy" |
| "${MOCK_CLANG_DIR}/bin/clang-apply-replacements" |
| "${MOCK_PYTHON3_DIR}/bin/python3" |
| "${MOCK_SHAC}" |
| "${FUCHSIA_BUILD_DIR}/host_x64/fidl-lint" |
| "${FUCHSIA_BUILD_DIR}/host_x64/clippy-reporter" |
| ) |
| |
| BT_MKDIR_DEPS=( |
| ".jiri_root" |
| ) |
| |
| BT_SET_UP() { |
| source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh" |
| fx="$(btf::setup_fx)" |
| |
| export PATH="${BT_TEMP_DIR}/bin:${PATH}" |
| cat > "${BT_TEMP_DIR}/tools/devshell/lib/platform.sh.mock_side_effects" <<INNER_EOF |
| readonly PREBUILT_CLANG_DIR=\${BT_TEMP_DIR}/${MOCK_CLANG_DIR} |
| readonly PREBUILT_SHAC=\${BT_TEMP_DIR}/${MOCK_SHAC} |
| readonly PREBUILT_PYTHON3_DIR=\${BT_TEMP_DIR}/${MOCK_PYTHON3_DIR} |
| INNER_EOF |
| } |
| |
| TEST_fx-lint-no-args() { |
| BT_EXPECT "${fx}" lint --dry-run 2> stderr |
| } |
| |
| TEST_fx-lint-commands() { |
| local out="${BT_TEMP_DIR}/_fx_lint_output" |
| local files=( |
| "${TESTDATA}/cplusplus.cc" |
| "${TESTDATA}/rust.rs" |
| "${TESTDATA}/fidl.test.fidl" |
| ) |
| local csfiles |
| printf -v csfiles ",%s" "${files[@]}" |
| BT_EXPECT "${fx}" lint --verbose --files="${csfiles:1}" > "${out}" |
| BT_EXPECT grep -q -E '"shac check .*/cplusplus.cc .*/rust.rs .*/fidl.test.fidl"' "${out}" |
| } |
| |
| TEST_fx-lint-fix-flag() { |
| local out="${BT_TEMP_DIR}/_fx_lint_output" |
| local files=( |
| "${TESTDATA}/rust.rs" |
| ) |
| local csfiles |
| printf -v csfiles ",%s" "${files[@]}" |
| BT_EXPECT "${fx}" lint --fix --verbose --files="${csfiles:1}" > "${out}" |
| BT_EXPECT grep -q -E '"shac fix .*/rust.rs"' "${out}" |
| } |
| |
| TEST_fx-lint-nonexistent-file() { |
| local err="${BT_TEMP_DIR}/_fx_lint_stderr" |
| local path="${TESTDATA}/doesnotexist.py" |
| BT_EXPECT "${fx}" lint --verbose --files="${path}" > /dev/null 2> "${err}" |
| BT_EXPECT grep -q -E '"ERROR: no such file: .*/doesnotexist.py"' "${err}" |
| } |
| |
| BT_RUN_TESTS "$@" |