From af3784ba24c294f3057a1c1c35f281df1074ff80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fr=C3=A9rot?= Date: Tue, 31 Dec 2024 14:01:49 +0100 Subject: [PATCH] added check-tree command --- rtenets | 36 ++++++++++++++++++++++++++++++++++++ tests/run_all_tests | 23 +++-------------------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/rtenets b/rtenets index 2028ea0..ddb58e4 100755 --- a/rtenets +++ b/rtenets @@ -282,6 +282,41 @@ create_tenet_file_tree() { script_stub make_all_figures "Generating figures..." } +# Check tree structure +check-tree() { + local directory="$1" + local check_failed=0 + pushd "${directory}" >/dev/null + + # Test directory is a git repo + if ! \git status > /dev/null 2>&1; then + warning "git failed: $PWD is not a repo" + check_failed=1 + fi + + # Test config values + if ! ( [[ "$(\git config user.name)" != "" ]] \ + && [[ "$(\git config user.email)" != "" ]] ); then + warning "git config failed" + check_failed=1 + fi + + # Test file structure + mandatory_files=("README.md~" + "AUTHORS" + "COPYING" + "make_all_figures" + "tests/run_all_tests") + for file in ${mandatory_files[*]}; do + if ! [[ -f "${file}" ]]; then + warning "file ${file} is missig" + check_failed=1 + fi + done + popd >/dev/null + return ${check_failed} +} + # ----------------- Gitea commands ----------------------- get_gitea_owner() { @@ -440,6 +475,7 @@ main() { [init-gitea]=init-gitea [init-workflow]=init-workflow [create]=create + [check-tree]=check-tree ) "${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}" diff --git a/tests/run_all_tests b/tests/run_all_tests index 0e975d1..dd007d6 100755 --- a/tests/run_all_tests +++ b/tests/run_all_tests @@ -6,26 +6,9 @@ source ../rtenets test_init-tree() { info "running test_init-tree" init-tree . - - # Test directory is a git repo - \git status > /dev/null 2>&1 \ - || ( echo "git failed: $PWD is not a repo"; exit 1 ) - - # Test config values - [[ "$(\git config user.name)" != "" ]] \ - && [[ "$(\git config user.email)" != "" ]] \ - || ( echo "git config failed"; exit 1 ) - - # Test file structure - mandatory_files=("README.md~" - "AUTHORS" - "COPYING" - "make_all_figures" - "tests/run_all_tests") - for file in ${mandatory_files[*]}; do - [[ -f "${file}" ]] || ( echo "file ${file} is missig"; exit 1 ) - done - info "finished test_init-tree" + check-tree . \ + && info "[✅] passed test_init-tree" \ + || warning "[❌] failed test_init-tree" }