From 53ef14352f9e1101972ca6fa22b19074321317fa Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 21 Mar 2023 10:31:11 +0100 Subject: Move end-to-end tests to a common place While for unit tests it is best practice to replicate the layout of the source tree, for end-to-end tests, this is less so. This is particularly true, as the distinction between the tests for two tools is a bit blurry; some tests for just still use just-mr as a launcher, and, e.g., the fetch test for just-mr uses just to carry out the garbage collection. Therefore, move all end-to-end tests together so that we also have a joinded target for precisely the end-to-end tests. In this reorganisation also indicate more explicitly which tests are also available for the bootstrap multi-repo tool. That information was so far hidden by the fact that in the other directory the tool dependency would not dispatch on TEST_BOOTSTRAP_JUST_MR. --- test/end-to-end/just-mr/TARGETS | 43 ++++- test/end-to-end/just-mr/create_test_archives.cpp | 133 +++++++++++++ test/end-to-end/just-mr/just-mr.test.sh | 212 +++++++++++++++++++++ test/end-to-end/just-mr/verbosity.sh | 101 ++++++++++ test/other_tools/TARGETS | 1 - test/other_tools/just_mr/TARGETS | 40 ---- test/other_tools/just_mr/create_test_archives.cpp | 133 ------------- test/other_tools/just_mr/just-mr.test.sh | 216 ---------------------- test/other_tools/just_mr/verbosity.sh | 101 ---------- 9 files changed, 488 insertions(+), 492 deletions(-) create mode 100644 test/end-to-end/just-mr/create_test_archives.cpp create mode 100644 test/end-to-end/just-mr/just-mr.test.sh create mode 100644 test/end-to-end/just-mr/verbosity.sh delete mode 100644 test/other_tools/just_mr/TARGETS delete mode 100644 test/other_tools/just_mr/create_test_archives.cpp delete mode 100644 test/other_tools/just_mr/just-mr.test.sh delete mode 100644 test/other_tools/just_mr/verbosity.sh (limited to 'test') diff --git a/test/end-to-end/just-mr/TARGETS b/test/end-to-end/just-mr/TARGETS index 417aee2c..d0f21d47 100644 --- a/test/end-to-end/just-mr/TARGETS +++ b/test/end-to-end/just-mr/TARGETS @@ -19,9 +19,50 @@ , ["test/end-to-end", "tool-under-test"] ] } +, "create_test_archives": + { "type": ["@", "rules", "CC", "binary"] + , "tainted": ["test"] + , "name": ["create_test_archives"] + , "srcs": ["create_test_archives.cpp"] + , "private-deps": + [ ["src/buildtool/file_system", "file_system_manager"] + , ["src/buildtool/logging", "logging"] + , ["src/other_tools/utils", "archive_ops"] + , ["src/utils/cpp", "tmp_dir"] + ] + , "private-ldflags": ["-pthread"] + , "stage": ["src"] + } +, "just_mr_mp": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["just_mr_mp"] + , "test": ["just-mr.test.sh"] + , "deps": + [ "create_test_archives" + , ["test/utils", "test_utils_install"] + , ["test/end-to-end", "mr-tool-under-test"] + ] + } +, "git-tree-verbosity": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["git-tree-verbosity"] + , "test": ["verbosity.sh"] + , "deps": [["test/end-to-end", "mr-tool-under-test"]] + } , "TESTS": { "type": "install" , "tainted": ["test"] - , "deps": ["cas-independent", "fetch", "fetch-gc"] + , "arguments_config": ["TEST_BOOTSTRAP_JUST_MR"] + , "deps": + { "type": "++" + , "$1": + [ ["cas-independent", "fetch", "fetch-gc"] + , { "type": "if" + , "cond": {"type": "var", "name": "TEST_BOOTSTRAP_JUST_MR"} + , "then": [] + , "else": ["just_mr_mp", "git-tree-verbosity"] + } + ] + } } } diff --git a/test/end-to-end/just-mr/create_test_archives.cpp b/test/end-to-end/just-mr/create_test_archives.cpp new file mode 100644 index 00000000..2f4327b7 --- /dev/null +++ b/test/end-to-end/just-mr/create_test_archives.cpp @@ -0,0 +1,133 @@ +// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "src/buildtool/file_system/file_system_manager.hpp" +#include "src/buildtool/logging/log_config.hpp" +#include "src/buildtool/logging/log_sink_cmdline.hpp" +#include "src/other_tools/utils/archive_ops.hpp" +#include "src/utils/cpp/tmp_dir.hpp" + +namespace { + +void SetupDefaultLogging() { + LogConfig::SetLogLimit(LogLevel::Progress); + LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()}); +} + +using file_t = std::pair; +using filetree_t = std::unordered_map; +/* +Structure of content tree: + ++--root + +--bar + +--foo + +--baz + +--bar + +--foo +*/ +auto const kExpected = filetree_t{{"root", {"", ObjectType::Tree}}, + {"root/foo", {"foo", ObjectType::File}}, + {"root/bar", {"bar", ObjectType::File}}, + {"root/baz", {"", ObjectType::Tree}}, + {"root/baz/foo", {"foo", ObjectType::File}}, + {"root/baz/bar", {"bar", ObjectType::File}}}; + +void create_files(std::filesystem::path const& destDir = ".") { + for (auto const& [path, file] : kExpected) { + auto const& [content, type] = file; + switch (type) { + case ObjectType::File: { + if (not FileSystemManager::WriteFile(content, destDir / path)) { + Logger::Log(LogLevel::Error, + "Could not create test file at path {}", + (destDir / path).string()); + std::exit(1); + }; + } break; + case ObjectType::Tree: { + if (not FileSystemManager::CreateDirectory(destDir / path)) { + Logger::Log(LogLevel::Error, + "Could not create test dir at path {}", + (destDir / path).string()); + std::exit(1); + }; + } break; + default: { + Logger::Log(LogLevel::Error, + "File system failure in creating test archive"); + std::exit(1); + } + } + } +} + +} // namespace + +/// \brief This code will create a zip and a tar.gz archives to be used in +/// tests. The archives are created in a tmp directory and then posted in the +/// current directory. Caller must guarantee write rights in current directory. +auto main() -> int { + // setup logging + SetupDefaultLogging(); + // make tmp dir + auto curr_path = FileSystemManager::GetCurrentDirectory(); + auto tmp_dir = TmpDir::Create(curr_path); + if (not tmp_dir) { + Logger::Log(LogLevel::Error, + "Could not create tmp dir for test archives at path {}", + curr_path.string()); + return 1; + } + // create the content tree + create_files(tmp_dir->GetPath()); + // create the archives + // 1. move to correct directory + { + auto anchor = FileSystemManager::ChangeDirectory(tmp_dir->GetPath()); + // 2. create the archives wrt to current directory + std::optional res{std::nullopt}; + res = ArchiveOps::CreateArchive( + ArchiveType::kArchiveTypeZip, "zip_repo.zip", "root"); + if (res) { + Logger::Log(LogLevel::Error, + "Creating test zip archive failed with:\n{}", + *res); + return 1; + } + res = ArchiveOps::CreateArchive( + ArchiveType::kArchiveTypeTarGz, "tgz_repo.tar.gz", "root"); + if (res) { + Logger::Log(LogLevel::Error, + "Creating test tar.gz archive failed with:\n{}", + *res); + return 1; + } + } // anchor released + // 3. move archives to their correct location + if (not FileSystemManager::Rename(tmp_dir->GetPath() / "zip_repo.zip", + "zip_repo.zip")) { + Logger::Log(LogLevel::Error, "Renaming zip archive failed"); + return 1; + } + if (not FileSystemManager::Rename(tmp_dir->GetPath() / "tgz_repo.tar.gz", + "tgz_repo.tar.gz")) { + Logger::Log(LogLevel::Error, "Renaming tar.gz archive failed"); + return 1; + } + // Done! Tmp dir will be cleaned automatically + return 0; +} diff --git a/test/end-to-end/just-mr/just-mr.test.sh b/test/end-to-end/just-mr/just-mr.test.sh new file mode 100644 index 00000000..fa18477c --- /dev/null +++ b/test/end-to-end/just-mr/just-mr.test.sh @@ -0,0 +1,212 @@ +#!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +# cleanup of http.server; pass server_pid as arg +server_cleanup() { + echo "Shut down HTTP server" + # send SIGTERM + kill ${1} & res=$! + wait ${res} + echo "done" +} + +readonly ROOT=`pwd` +readonly WRKDIR="${TEST_TMPDIR}/wrkdir" + +readonly JUST_MR_CPP="${ROOT}/bin/mr-tool-under-test" + +# set paths +readonly SERVER_ROOT="${TEST_TMPDIR}/server-root" +readonly FILE_ROOT="${TEST_TMPDIR}/file-root" +readonly GIT_ROOT="${TEST_TMPDIR}/git-root" +readonly TEST_ROOT="${TEST_TMPDIR}/test-root" + +# move to where server will be posted +mkdir -p "${SERVER_ROOT}" +cd "${SERVER_ROOT}" + +echo "Setup archive repos" +# create the archives in current dir +${ROOT}/src/create_test_archives + +# store zip repo info +readonly ZIP_REPO_CONTENT=$(git hash-object zip_repo.zip) +readonly ZIP_REPO_SHA256=$(sha256sum zip_repo.zip | awk '{print $1}') +readonly ZIP_REPO_SHA512=$(sha512sum zip_repo.zip | awk '{print $1}') +# store tar.gz repo info +readonly TGZ_REPO_CONTENT=$(git hash-object tgz_repo.tar.gz) +readonly TGZ_REPO_SHA256=$(sha256sum tgz_repo.tar.gz | awk '{print $1}') +readonly TGZ_REPO_SHA512=$(sha512sum tgz_repo.tar.gz | awk '{print $1}') + +echo "Set up file repos" +mkdir -p "${FILE_ROOT}/test_dir1" +echo test > "${FILE_ROOT}/test_dir1/test_file" +mkdir -p "${FILE_ROOT}/test_dir2/test_dir3" +echo test > "${FILE_ROOT}/test_dir2/test_dir3/test_file" + +echo "Set up local git repo" +# NOTE: Libgit2 has no support for Git bundles yet +mkdir -p "${GIT_ROOT}" +mkdir -p bin +cat > bin/git_dir_setup.sh < foo.txt +echo bar > foo/bar.txt +echo baz > foo/bar/baz.txt +EOF +# set up git repo +( + cd "${GIT_ROOT}" \ + && sh "${SERVER_ROOT}/bin/git_dir_setup.sh" \ + && git init -b test \ + && git config user.email "nobody@example.org" \ + && git config user.name "Nobody" \ + && git add . \ + && git commit -m "test" --date="1970-01-01T00:00Z" +) +readonly GIT_REPO_COMMIT="$(cd "${GIT_ROOT}" && git rev-parse HEAD)" + +echo "Set up git tree repo" +# get tree id; only the content of the directory structure matters +readonly GIT_TREE_ID="$(cd "${GIT_ROOT}" && git ls-tree "${GIT_REPO_COMMIT}" foo/bar | awk '{print $3}')" + +echo "Publish remote repos to HTTP server" +# start Python server as remote repos location +port_file="$(mktemp -t port_XXXXXX -p "${TEST_TMPDIR}")" +python3 -u "${ROOT}/utils/run_test_server.py" >${port_file} & server_pid=$! +sleep 1s # give some time to set up properly +# set up cleanup of http server +trap "server_cleanup ${server_pid}" INT TERM EXIT +# get port number as variable +port_num="$(cat ${port_file})" + +echo "Create local build env" +# the build root +readonly BUILDROOT=${WRKDIR}/.cache/just +mkdir -p ${BUILDROOT} +# a distdir +readonly DISTFILES=${WRKDIR}/.distfiles +mkdir -p ${DISTFILES} +readonly DISTDIR_ARGS="--distdir ${DISTFILES}" + +echo "Create repos.json" +mkdir -p "${TEST_ROOT}" +cd "${TEST_ROOT}" +cat > test-repos.json < test_setup.sh < "${TOOL}" <&2 +echo {} > TARGETS +if [ -n "\${SHOULD_FAIL:-}" ] +then + exit 0 +fi +echo data > foo.txt +EOF +chmod 755 "${TOOL}" +mkdir -p "${COMPUTE_TREE_DIR}" +( cd "${COMPUTE_TREE_DIR}" + git init + git config user.email "nobody@example.org" + git config user.name "Nobody" + "${TOOL}" + git add . + git commit -m "Sample output" +) +readonly TREE_ID=$(cd "${COMPUTE_TREE_DIR}" && git log -n 1 --format="%T") +rm -rf "${COMPUTE_TREE_DIR}" + +# Set up workspace + +touch ROOT +cat > repos.json <log && exit 1 || : +cat log +grep -q -F "${TOOL_MSG_A}" log +grep -q -F "${TOOL_MSG_B}" log +grep -q -F "SHOULD_FAIL=YES" log +grep -q -F "${TOOL}" log + +# On success, everything should be quiet (despite the command +# potentially producing output) + +echo +echo testing setup success +echo + +CONF=$("${JUST_MR}" --local-build-root "${LBR}" \ + -L '["env", "SHOULD_FAIL="]' setup 2>log) +cat log +echo "${CONF}" +cat "${CONF}" +echo +grep -F "${TOOL_MSG_A}" log && exit 1 || : +grep -F "${TOOL_MSG_B}" log && exit 1 || : +grep -F "${TOOL}" log && exit 1 || : +# sanity check: the generated configuration contains the requested tree +grep -q -F "${TREE_ID}" "${CONF}" + +echo OK diff --git a/test/other_tools/TARGETS b/test/other_tools/TARGETS index a5ad01be..8d2ec2e7 100644 --- a/test/other_tools/TARGETS +++ b/test/other_tools/TARGETS @@ -3,7 +3,6 @@ , "tainted": ["test"] , "dirs": [ [["./", "git_operations", "TESTS"], "git_operations"] - , [["./", "just_mr", "TESTS"], "just_mr"] , [["./", "utils", "TESTS"], "utils"] ] } diff --git a/test/other_tools/just_mr/TARGETS b/test/other_tools/just_mr/TARGETS deleted file mode 100644 index 699abed8..00000000 --- a/test/other_tools/just_mr/TARGETS +++ /dev/null @@ -1,40 +0,0 @@ -{ "just_mr_install": - { "type": "install" - , "files": {"bin/just-mr-under-test": ["src/other_tools/just_mr", "just-mr"]} - } -, "create_test_archives": - { "type": ["@", "rules", "CC", "binary"] - , "tainted": ["test"] - , "name": ["create_test_archives"] - , "srcs": ["create_test_archives.cpp"] - , "private-deps": - [ ["src/buildtool/file_system", "file_system_manager"] - , ["src/buildtool/logging", "logging"] - , ["src/other_tools/utils", "archive_ops"] - , ["src/utils/cpp", "tmp_dir"] - ] - , "private-ldflags": ["-pthread"] - , "stage": ["src"] - } -, "just_mr_mp": - { "type": ["@", "rules", "shell/test", "script"] - , "name": ["just_mr_mp"] - , "test": ["just-mr.test.sh"] - , "deps": - [ "create_test_archives" - , ["test/utils", "test_utils_install"] - , "just_mr_install" - ] - } -, "git-tree-verbosity": - { "type": ["@", "rules", "shell/test", "script"] - , "name": ["git-tree-verbosity"] - , "test": ["verbosity.sh"] - , "deps": ["just_mr_install"] - } -, "TESTS": - { "type": "install" - , "tainted": ["test"] - , "deps": ["just_mr_mp", "git-tree-verbosity"] - } -} diff --git a/test/other_tools/just_mr/create_test_archives.cpp b/test/other_tools/just_mr/create_test_archives.cpp deleted file mode 100644 index 2f4327b7..00000000 --- a/test/other_tools/just_mr/create_test_archives.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "src/buildtool/file_system/file_system_manager.hpp" -#include "src/buildtool/logging/log_config.hpp" -#include "src/buildtool/logging/log_sink_cmdline.hpp" -#include "src/other_tools/utils/archive_ops.hpp" -#include "src/utils/cpp/tmp_dir.hpp" - -namespace { - -void SetupDefaultLogging() { - LogConfig::SetLogLimit(LogLevel::Progress); - LogConfig::SetSinks({LogSinkCmdLine::CreateFactory()}); -} - -using file_t = std::pair; -using filetree_t = std::unordered_map; -/* -Structure of content tree: - -+--root - +--bar - +--foo - +--baz - +--bar - +--foo -*/ -auto const kExpected = filetree_t{{"root", {"", ObjectType::Tree}}, - {"root/foo", {"foo", ObjectType::File}}, - {"root/bar", {"bar", ObjectType::File}}, - {"root/baz", {"", ObjectType::Tree}}, - {"root/baz/foo", {"foo", ObjectType::File}}, - {"root/baz/bar", {"bar", ObjectType::File}}}; - -void create_files(std::filesystem::path const& destDir = ".") { - for (auto const& [path, file] : kExpected) { - auto const& [content, type] = file; - switch (type) { - case ObjectType::File: { - if (not FileSystemManager::WriteFile(content, destDir / path)) { - Logger::Log(LogLevel::Error, - "Could not create test file at path {}", - (destDir / path).string()); - std::exit(1); - }; - } break; - case ObjectType::Tree: { - if (not FileSystemManager::CreateDirectory(destDir / path)) { - Logger::Log(LogLevel::Error, - "Could not create test dir at path {}", - (destDir / path).string()); - std::exit(1); - }; - } break; - default: { - Logger::Log(LogLevel::Error, - "File system failure in creating test archive"); - std::exit(1); - } - } - } -} - -} // namespace - -/// \brief This code will create a zip and a tar.gz archives to be used in -/// tests. The archives are created in a tmp directory and then posted in the -/// current directory. Caller must guarantee write rights in current directory. -auto main() -> int { - // setup logging - SetupDefaultLogging(); - // make tmp dir - auto curr_path = FileSystemManager::GetCurrentDirectory(); - auto tmp_dir = TmpDir::Create(curr_path); - if (not tmp_dir) { - Logger::Log(LogLevel::Error, - "Could not create tmp dir for test archives at path {}", - curr_path.string()); - return 1; - } - // create the content tree - create_files(tmp_dir->GetPath()); - // create the archives - // 1. move to correct directory - { - auto anchor = FileSystemManager::ChangeDirectory(tmp_dir->GetPath()); - // 2. create the archives wrt to current directory - std::optional res{std::nullopt}; - res = ArchiveOps::CreateArchive( - ArchiveType::kArchiveTypeZip, "zip_repo.zip", "root"); - if (res) { - Logger::Log(LogLevel::Error, - "Creating test zip archive failed with:\n{}", - *res); - return 1; - } - res = ArchiveOps::CreateArchive( - ArchiveType::kArchiveTypeTarGz, "tgz_repo.tar.gz", "root"); - if (res) { - Logger::Log(LogLevel::Error, - "Creating test tar.gz archive failed with:\n{}", - *res); - return 1; - } - } // anchor released - // 3. move archives to their correct location - if (not FileSystemManager::Rename(tmp_dir->GetPath() / "zip_repo.zip", - "zip_repo.zip")) { - Logger::Log(LogLevel::Error, "Renaming zip archive failed"); - return 1; - } - if (not FileSystemManager::Rename(tmp_dir->GetPath() / "tgz_repo.tar.gz", - "tgz_repo.tar.gz")) { - Logger::Log(LogLevel::Error, "Renaming tar.gz archive failed"); - return 1; - } - // Done! Tmp dir will be cleaned automatically - return 0; -} diff --git a/test/other_tools/just_mr/just-mr.test.sh b/test/other_tools/just_mr/just-mr.test.sh deleted file mode 100644 index 3c1f669a..00000000 --- a/test/other_tools/just_mr/just-mr.test.sh +++ /dev/null @@ -1,216 +0,0 @@ -#!/bin/sh -# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eu - -# cleanup of http.server; pass server_pid as arg -server_cleanup() { - echo "Shut down HTTP server" - # send SIGTERM - kill ${1} & res=$! - wait ${res} - echo "done" -} - -readonly ROOT=`pwd` -readonly WRKDIR="${TEST_TMPDIR}/wrkdir" - -# set the just-mr versions to be run -# Python version won't be able to find wget, unzip, and tar - -# readonly JUST_MR_PY="${ROOT}/bin/just-mr.py" -readonly JUST_MR_CPP="${ROOT}/bin/just-mr-under-test" - -# set paths -readonly SERVER_ROOT="${TEST_TMPDIR}/server-root" -readonly FILE_ROOT="${TEST_TMPDIR}/file-root" -readonly GIT_ROOT="${TEST_TMPDIR}/git-root" -readonly TEST_ROOT="${TEST_TMPDIR}/test-root" - -# move to where server will be posted -mkdir -p "${SERVER_ROOT}" -cd "${SERVER_ROOT}" - -echo "Setup archive repos" -# create the archives in current dir -${ROOT}/src/create_test_archives - -# store zip repo info -readonly ZIP_REPO_CONTENT=$(git hash-object zip_repo.zip) -readonly ZIP_REPO_SHA256=$(sha256sum zip_repo.zip | awk '{print $1}') -readonly ZIP_REPO_SHA512=$(sha512sum zip_repo.zip | awk '{print $1}') -# store tar.gz repo info -readonly TGZ_REPO_CONTENT=$(git hash-object tgz_repo.tar.gz) -readonly TGZ_REPO_SHA256=$(sha256sum tgz_repo.tar.gz | awk '{print $1}') -readonly TGZ_REPO_SHA512=$(sha512sum tgz_repo.tar.gz | awk '{print $1}') - -echo "Set up file repos" -mkdir -p "${FILE_ROOT}/test_dir1" -echo test > "${FILE_ROOT}/test_dir1/test_file" -mkdir -p "${FILE_ROOT}/test_dir2/test_dir3" -echo test > "${FILE_ROOT}/test_dir2/test_dir3/test_file" - -echo "Set up local git repo" -# NOTE: Libgit2 has no support for Git bundles yet -mkdir -p "${GIT_ROOT}" -mkdir -p bin -cat > bin/git_dir_setup.sh < foo.txt -echo bar > foo/bar.txt -echo baz > foo/bar/baz.txt -EOF -# set up git repo -( - cd "${GIT_ROOT}" \ - && sh "${SERVER_ROOT}/bin/git_dir_setup.sh" \ - && git init -b test \ - && git config user.email "nobody@example.org" \ - && git config user.name "Nobody" \ - && git add . \ - && git commit -m "test" --date="1970-01-01T00:00Z" -) -readonly GIT_REPO_COMMIT="$(cd "${GIT_ROOT}" && git rev-parse HEAD)" - -echo "Set up git tree repo" -# get tree id; only the content of the directory structure matters -readonly GIT_TREE_ID="$(cd "${GIT_ROOT}" && git ls-tree "${GIT_REPO_COMMIT}" foo/bar | awk '{print $3}')" - -echo "Publish remote repos to HTTP server" -# start Python server as remote repos location -port_file="$(mktemp -t port_XXXXXX -p "${TEST_TMPDIR}")" -python3 -u "${ROOT}/utils/run_test_server.py" >${port_file} & server_pid=$! -sleep 1s # give some time to set up properly -# set up cleanup of http server -trap "server_cleanup ${server_pid}" INT TERM EXIT -# get port number as variable -port_num="$(cat ${port_file})" - -echo "Create local build env" -# the build root -readonly BUILDROOT=${WRKDIR}/.cache/just -mkdir -p ${BUILDROOT} -# a distdir -readonly DISTFILES=${WRKDIR}/.distfiles -mkdir -p ${DISTFILES} -readonly DISTDIR_ARGS="--distdir ${DISTFILES}" - -echo "Create repos.json" -mkdir -p "${TEST_ROOT}" -cd "${TEST_ROOT}" -cat > test-repos.json < test_setup.sh < "${TOOL}" <&2 -echo {} > TARGETS -if [ -n "\${SHOULD_FAIL:-}" ] -then - exit 0 -fi -echo data > foo.txt -EOF -chmod 755 "${TOOL}" -mkdir -p "${COMPUTE_TREE_DIR}" -( cd "${COMPUTE_TREE_DIR}" - git init - git config user.email "nobody@example.org" - git config user.name "Nobody" - "${TOOL}" - git add . - git commit -m "Sample output" -) -readonly TREE_ID=$(cd "${COMPUTE_TREE_DIR}" && git log -n 1 --format="%T") -rm -rf "${COMPUTE_TREE_DIR}" - -# Set up workspace - -touch ROOT -cat > repos.json <log && exit 1 || : -cat log -grep -q -F "${TOOL_MSG_A}" log -grep -q -F "${TOOL_MSG_B}" log -grep -q -F "SHOULD_FAIL=YES" log -grep -q -F "${TOOL}" log - -# On success, everything should be quiet (despite the command -# potentially producing output) - -echo -echo testing setup success -echo - -CONF=$("${JUST_MR}" --local-build-root "${LBR}" \ - -L '["env", "SHOULD_FAIL="]' setup 2>log) -cat log -echo "${CONF}" -cat "${CONF}" -echo -grep -F "${TOOL_MSG_A}" log && exit 1 || : -grep -F "${TOOL_MSG_B}" log && exit 1 || : -grep -F "${TOOL}" log && exit 1 || : -# sanity check: the generated configuration contains the requested tree -grep -q -F "${TREE_ID}" "${CONF}" - -echo OK -- cgit v1.2.3