blob: f89f0ed2acbc652b88213c2dd05ab17731ed5145 [file]
#!/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 expected behavior of fx-build-config-load in vars.sh
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/lib/vars.sh"
"tools/devshell/lib/is_invoked_by_agent.sh"
"tools/devshell/lib/agents.txt"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/lib/generate-ssh-config.sh"
"tools/devshell/tests/lib/fuchsia-mock.sh"
)
declare fx
BT_SET_UP() {
source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh"
fx="$(btf::setup_fx)"
FUCHSIA_DIR="${BT_TEMP_DIR}"
}
TEST_fx-config-load-suggests-gen-when-args-gn-exists() {
mkdir -p "${FUCHSIA_DIR}/out/default"
echo "out/default" > "${FUCHSIA_DIR}/.fx-build-dir"
echo "some_arg = true" > "${FUCHSIA_DIR}/out/default/args.gn"
echo "syntax error (" > "${FUCHSIA_DIR}/out/default/fx.config"
local out="${BT_TEMP_DIR}/_output"
bash -c "
export FUCHSIA_DIR='${FUCHSIA_DIR}';
source '${FUCHSIA_DIR}/tools/devshell/lib/vars.sh';
fx-config-read
" >"$out" 2>&1
BT_EXPECT_FILE_CONTAINS "$out" "${FUCHSIA_DIR}/out/default/fx.config: line 1: syntax error near unexpected token \`('
${FUCHSIA_DIR}/out/default/fx.config: line 1: \`syntax error ('
ERROR: Sourcing ${FUCHSIA_DIR}/out/default/fx.config caused internal error
ERROR: Try running 'fx gen' to regenerate your build configuration."
}
TEST_fx-config-load-suggests-set-when-args-gn-missing() {
mkdir -p "${FUCHSIA_DIR}/out/default"
echo "out/default" > "${FUCHSIA_DIR}/.fx-build-dir"
# Do not create args.gn
rm -f "${FUCHSIA_DIR}/out/default/args.gn"
echo "syntax error (" > "${FUCHSIA_DIR}/out/default/fx.config"
local out="${BT_TEMP_DIR}/_output"
bash -c "
export FUCHSIA_DIR='${FUCHSIA_DIR}';
source '${FUCHSIA_DIR}/tools/devshell/lib/vars.sh';
fx-config-read
" >"$out" 2>&1
BT_EXPECT_FILE_CONTAINS "$out" "${FUCHSIA_DIR}/out/default/fx.config: line 1: syntax error near unexpected token \`('
${FUCHSIA_DIR}/out/default/fx.config: line 1: \`syntax error ('
ERROR: Sourcing ${FUCHSIA_DIR}/out/default/fx.config caused internal error
ERROR: Try running 'fx set' to generate a new build configuration."
}
BT_RUN_TESTS "$@"