| #!/bin/bash |
| # 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. |
| |
| ### Test expected behavior of `fx report-bug`. |
| |
| export BT_FILE_DEPS=( |
| "scripts/fx" |
| "tools/devshell/report-bug" |
| "tools/devshell/lib/fx-cmd-locator.sh" |
| "tools/devshell/lib/fx-optional-features.sh" |
| "tools/devshell/lib/vars.sh" |
| "tools/devshell/lib/platform.sh" |
| ) |
| |
| BT_SET_UP() { |
| # shellcheck source=/dev/null |
| source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh" |
| fx="$(btf::setup_fx)" |
| } |
| |
| # Ensure that "fx report-bug --help" and friends run and emit help. |
| TEST_report_bug_help() { |
| BT_EXPECT "${fx}" report-bug --help &>_out1 |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING _out1 "Report an issue on an fx <command>." |
| BT_EXPECT "${fx}" report-bug -h &>_out2 |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING _out2 "Report an issue on an fx <command>." |
| BT_EXPECT "${fx}" report-bug &>_out3 |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING _out3 "Report an issue on an fx <command>." |
| } |
| |
| TEST_nothing_in_devshell_owners() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| # nothing here |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "Tools%3efx" # Default component. |
| BT_EXPECT_FILE_DOES_NOT_CONTAIN_SUBSTRING "${out}" "cc=" # no per-file, so empty. |
| } |
| |
| TEST_per_file_component_in_devshell_owners() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| # per-file-COMPONENT report-bug=foo |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=foo" |
| BT_EXPECT_FILE_DOES_NOT_CONTAIN_SUBSTRING "${out}" "cc=" |
| } |
| |
| TEST_per_file_owners_in_devshell_owners() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=foo |
| # per-file-COMPONENT report-bug=bar |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=foo" |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=bar" |
| } |
| |
| TEST_both_in_devshell_owners() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=foo |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=foo" |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=Tools%3efx" # Default component. |
| } |
| |
| TEST_contrib_commands() { |
| mkdir "${BT_TEMP_DIR}/tools/devshell/contrib" |
| cat >"${BT_TEMP_DIR}/tools/devshell/contrib/test-command" <<EOF |
| #!/bin/bash |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-info "test command" |
| EOF |
| chmod u+x "${BT_TEMP_DIR}/tools/devshell/contrib/test-command" |
| |
| local out="_fx_report_bug_output" |
| cat >"${BT_TEMP_DIR}/tools/devshell/contrib/OWNERS" <<EOF |
| # nothing here |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| # per-file-COMPONENT test-command=foo3 |
| EOF |
| BT_EXPECT "${fx}" report-bug test-command &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=Tools%3efx" # Not picked from parent dir. |
| BT_EXPECT_FILE_DOES_NOT_CONTAIN_SUBSTRING "${out}" "cc=" # no per-file, so empty. |
| } |
| |
| TEST_contrib_commands2() { |
| mkdir "${BT_TEMP_DIR}/tools/devshell/contrib" |
| cat >"${BT_TEMP_DIR}/tools/devshell/contrib/test-command" <<EOF |
| #!/bin/bash |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-info "test command" |
| EOF |
| chmod u+x "${BT_TEMP_DIR}/tools/devshell/contrib/test-command" |
| |
| local out="_fx_report_bug_output" |
| cat >"${BT_TEMP_DIR}/tools/devshell/contrib/OWNERS" <<EOF |
| # per-file-COMPONENT test-command=foo3 |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file test-command=bar |
| EOF |
| BT_EXPECT "${fx}" report-bug test-command &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=foo3" |
| BT_EXPECT_FILE_DOES_NOT_CONTAIN_SUBSTRING "${out}" "cc=" # Not picked from parent dir. |
| } |
| |
| TEST_multiple_lines() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=foo |
| per-file report-bug=bar # An additional comment. |
| # per-file-COMPONENT report-bug=baz # An additional comment. |
| # per-file-COMPONENT report-bug=bop # An additional comment. |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=bar%2cfoo" # Note: alphabetized. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=baz%2cbop" |
| } |
| |
| TEST_dot_fx_lines() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=foo |
| per-file report-bug.fx=bim,bar # Additional .fx owners. |
| # per-file-COMPONENT report-bug=baz # |
| # per-file-COMPONENT report-bug.fx=bop # An additional .fx component. |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=bar%2cbim%2cfoo" # Note: alphabetized. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=baz%2cbop" |
| } |
| |
| TEST_multiple_lines_and_spacings() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=a |
| per-file report-bug=b |
| per-file report-bug =c ,e,d |
| per-file report-bug = h , g , f , # comma and comment to be stripped |
| #per-file-COMPONENT report-bug=z,y |
| # per-file-COMPONENT report-bug=u , w, v, x |
| # per-file-COMPONENT report-bug = s,s,t ,t ,t # duplicates on same line. |
| # per-file-COMPONENT report-bug = s,s,t ,t ,t # duplicate line, mostly. |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=a%2cb%2cc%2cd%2ce%2cf%2cg%2ch" # a,b,c,d,e,f,g,h |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=s%2ct%2cu%2cv%2cw%2cx%2cy%2cz" # s,t,u,v,w,x,y,z |
| } |
| |
| TEST_OWNERS_component() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| #COMPONENT: s,s,t ,t ,t # duplicates on same line. |
| # COMPONENT: s,z,v,x |
| # COMPONENT : w, u, y, z |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_DOES_NOT_CONTAIN_SUBSTRING "${out}" "cc=" # no per-file, so empty. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=s%2ct%2cu%2cv%2cw%2cx%2cy%2cz" # s,t,u,v,w,x,y,z |
| } |
| |
| TEST_OWNERS_list() { |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=Tools%3efx" # Default component. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=s1%40g.com%2cs%40g.com%2ct%40g.com" |
| } |
| |
| TEST_OWNERS_file_directive() { |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file: report-bug= file:/foo/OWNERS |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=Tools%3efx" # Default component. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=s1%40g.com%2cs%40g.com%2ct%40g.com" |
| } |
| |
| TEST_OWNERS_include_directive() { |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>bar |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| include /foo/OWNERS |
| # COMPONENT: t>bim # This component overrides. |
| z@g.com # This owner appends. |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=t%3ebim" # Default component. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=z%40g.com" |
| } |
| |
| # The per-file-COMPONENT is found and not overridden by the component in the the |
| # per-file file. |
| TEST_OWNERS_file_directive_and_per_file_component() { |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>bar |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=file:/foo/OWNERS |
| #per-file-COMPONENT report-bug=FT>y |
| # COMPONENT: t>bim |
| z@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=FT%3ey" |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=s1%40g.com%2cs%40g.com%2ct%40g.com" |
| } |
| |
| TEST_OWNERS_deep() { |
| mkdir "${BT_TEMP_DIR}/bar" |
| cat >"${BT_TEMP_DIR}/bar/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>baz |
| EOF |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| include /bar/OWNERS |
| # COMPONENT: t>bar |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=file:/foo/OWNERS |
| #per-file-COMPONENT report-bug=FT>y |
| # COMPONENT: t>bim |
| z@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| # WRONG: Should be FT>y. per-file-COMPONENT should be preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=FT%3ey" |
| # Right: file authors preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=s1%40g.com%2cs%40g.com%2ct%40g.com" |
| } |
| |
| # In this test, the top-level OWNERS has a per-file owners, so that overrides |
| # the z@g.com listed there. That per-file OWNERS (foo/) has an owner, x@g.com, |
| # so that is used and the other owners found in its include file are ignored. |
| # Also, the per-file-COMPONENT is not overridden by includes. |
| TEST_OWNERS_deep2() { |
| mkdir "${BT_TEMP_DIR}/bar" |
| cat >"${BT_TEMP_DIR}/bar/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>baz |
| EOF |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| include /bar/OWNERS |
| # COMPONENT: t>bar |
| x@g.com |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=file:/foo/OWNERS |
| #per-file-COMPONENT report-bug=FT>y |
| # COMPONENT: t>bim |
| z@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| # WRONG: Should be FT>y. per-file-COMPONENT should be preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=FT%3ey" |
| # Right: file authors preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=x%40g.com" |
| } |
| |
| # Here the per-file owners and component go one deep. |
| TEST_OWNERS_deep3() { |
| mkdir "${BT_TEMP_DIR}/bar" |
| cat >"${BT_TEMP_DIR}/bar/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>baz |
| EOF |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| include /bar/OWNERS |
| # COMPONENT: t>bar |
| x@g.com |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=file:/foo/OWNERS |
| # COMPONENT: t>bim |
| z@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| # WRONG: Should be FT>y. per-file-COMPONENT should be preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=t%3ebar" |
| # Right: file authors preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=x%40g.com" |
| } |
| |
| # Here the per-file owners and component go into the include file |
| # because there are not owners or component in the perf-file file. |
| TEST_OWNERS_deep4() { |
| mkdir "${BT_TEMP_DIR}/bar" |
| cat >"${BT_TEMP_DIR}/bar/OWNERS" <<EOF |
| t@g.com |
| s@g.com # comment. |
| s1@g.com |
| # COMPONENT: t>baz |
| EOF |
| mkdir "${BT_TEMP_DIR}/foo" |
| cat >"${BT_TEMP_DIR}/foo/OWNERS" <<EOF |
| include /bar/OWNERS |
| EOF |
| cat >"${BT_TEMP_DIR}/tools/devshell/OWNERS" <<EOF |
| per-file report-bug=file:/foo/OWNERS |
| # COMPONENT: t>bim |
| z@g.com |
| EOF |
| local out="_fx_report_bug_output" |
| BT_EXPECT "${fx}" report-bug -v report-bug &>${out} |
| # WRONG: Should be FT>y. per-file-COMPONENT should be preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "components=t%3ebaz" |
| # Right: file authors preferred. |
| BT_EXPECT_FILE_CONTAINS_SUBSTRING "${out}" "cc=s1%40g.com%2cs%40g.com%2ct%40g.com" |
| } |
| |
| BT_RUN_TESTS "$@" |