diff --git a/plain2code.py b/plain2code.py index 4a60558..a4838a5 100644 --- a/plain2code.py +++ b/plain2code.py @@ -261,6 +261,12 @@ def run_render(): def main(): # noqa: C901 args = parse_arguments() + # Anchor all relative paths to the plain file's directory. + # Resolve filename to absolute first (it may be relative to the original CWD), + # then change CWD so that all subsequent relative paths (build_folder, etc.) resolve correctly. + args.filename = os.path.abspath(args.filename) + os.chdir(os.path.dirname(args.filename)) + # Handle early-exit flags before heavy initialization if args.dry_run or args.full_plain: template_dirs = file_utils.get_template_directories(args.filename, args.template_dir, DEFAULT_TEMPLATE_DIRS) diff --git a/test_scripts/run_conformance_tests_cypress.sh b/test_scripts/run_conformance_tests_cypress.sh index a3af59c..d449c85 100755 --- a/test_scripts/run_conformance_tests_cypress.sh +++ b/test_scripts/run_conformance_tests_cypress.sh @@ -89,14 +89,12 @@ if [[ "$3" == "-v" || "$3" == "--verbose" ]]; then VERBOSE=1 fi -current_dir=$(pwd) - # Ensures that if any command in the pipeline fails (like npm run build), the entire pipeline # will return a non-zero status, allowing the if condition to properly catch failures. set -o pipefail # Define the path to the subfolder -NODE_SUBFOLDER=node_$1 +NODE_SUBFOLDER=$(dirname "$1")/node_$(basename "$1") # Running React application printf "### Step 1: Starting the React application in folder $NODE_SUBFOLDER...\n" @@ -121,7 +119,7 @@ else mkdir -p $NODE_SUBFOLDER fi -cp -R $1/* $NODE_SUBFOLDER +cp -R "$1"/* $NODE_SUBFOLDER # Move to the subfolder cd "$NODE_SUBFOLDER" 2>/dev/null @@ -202,11 +200,8 @@ fi # Execute all Cypress conformance tests in the build folder printf "### Step 2: Running Cypress conformance tests $2...\n" -# Move back to the original directory -cd $current_dir - # Define the path to the conformance tests subfolder -NODE_CONFORMANCE_TESTS_SUBFOLDER=node_$2 +NODE_CONFORMANCE_TESTS_SUBFOLDER=$(dirname "$2")/node_$(basename "$2") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing conformance tests Node subfolder: $NODE_CONFORMANCE_TESTS_SUBFOLDER\n" @@ -228,7 +223,7 @@ else mkdir -p $NODE_CONFORMANCE_TESTS_SUBFOLDER fi -cp -R $2/* $NODE_CONFORMANCE_TESTS_SUBFOLDER +cp -R "$2"/* $NODE_CONFORMANCE_TESTS_SUBFOLDER # Move to the subfolder with Cypress tests cd "$NODE_CONFORMANCE_TESTS_SUBFOLDER" 2>/dev/null diff --git a/test_scripts/run_conformance_tests_golang.sh b/test_scripts/run_conformance_tests_golang.sh index 1832241..7224502 100755 --- a/test_scripts/run_conformance_tests_golang.sh +++ b/test_scripts/run_conformance_tests_golang.sh @@ -16,9 +16,7 @@ if [ -z "$2" ]; then exit $UNRECOVERABLE_ERROR_EXIT_CODE fi -current_dir=$(pwd) - -GO_BUILD_SUBFOLDER=go_$1 +GO_BUILD_SUBFOLDER=$(dirname "$1")/go_$(basename "$1") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing Go build subfolder: $GO_BUILD_SUBFOLDER\n" @@ -40,7 +38,7 @@ else mkdir -p $GO_BUILD_SUBFOLDER fi -cp -R $1/* $GO_BUILD_SUBFOLDER +cp -R "$1"/* $GO_BUILD_SUBFOLDER # Move to the subfolder cd "$GO_BUILD_SUBFOLDER" 2>/dev/null @@ -53,10 +51,10 @@ fi echo "Runinng go get in the build folder..." go get -cd "$current_dir/$2" 2>/dev/null +cd "$2" 2>/dev/null if [ $? -ne 0 ]; then - printf "Error: Conformance tests folder '$current_dir/$2' does not exist.\n" + printf "Error: Conformance tests folder '$2' does not exist.\n" exit $UNRECOVERABLE_ERROR_EXIT_CODE fi @@ -69,12 +67,12 @@ else fi # Move back to build directory -cd "$current_dir/$GO_BUILD_SUBFOLDER" 2>/dev/null +cd "$GO_BUILD_SUBFOLDER" 2>/dev/null # Execute Go lang conformance tests printf "Running Golang conformance tests...\n\n" -output=$(go run $current_dir/$2/conformance_tests.go 2>&1) +output=$(go run "$2"/conformance_tests.go 2>&1) exit_code=$? # If there was an error, print the output and exit with the error code diff --git a/test_scripts/run_conformance_tests_python.sh b/test_scripts/run_conformance_tests_python.sh index 5c685e1..9876f80 100755 --- a/test_scripts/run_conformance_tests_python.sh +++ b/test_scripts/run_conformance_tests_python.sh @@ -26,9 +26,7 @@ else exit $UNRECOVERABLE_ERROR_EXIT_CODE fi -current_dir=$(pwd) - -PYTHON_BUILD_SUBFOLDER=python_$1 +PYTHON_BUILD_SUBFOLDER=$(dirname "$1")/python_$(basename "$1") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing Python build subfolder: $PYTHON_BUILD_SUBFOLDER\n" @@ -50,7 +48,7 @@ else mkdir -p $PYTHON_BUILD_SUBFOLDER fi -cp -R $1/* $PYTHON_BUILD_SUBFOLDER +cp -R "$1"/* $PYTHON_BUILD_SUBFOLDER # Move to the subfolder cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null @@ -63,7 +61,7 @@ fi # Execute all Python conformance tests in the build folder printf "Running Python conformance tests...\n\n" -output=$($PYTHON_CMD -m unittest discover -b -s "$current_dir/$2" 2>&1) +output=$($PYTHON_CMD -m unittest discover -b -s "$2" 2>&1) exit_code=$? # Echo the original output diff --git a/test_scripts/run_unittests_golang.sh b/test_scripts/run_unittests_golang.sh index 56da7f1..82b8646 100755 --- a/test_scripts/run_unittests_golang.sh +++ b/test_scripts/run_unittests_golang.sh @@ -9,7 +9,7 @@ if [ -z "$1" ]; then exit $UNRECOVERABLE_ERROR_EXIT_CODE fi -GO_BUILD_SUBFOLDER=go_$1 +GO_BUILD_SUBFOLDER=$(dirname "$1")/go_$(basename "$1") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing Go build subfolder: $GO_BUILD_SUBFOLDER\n" @@ -31,7 +31,7 @@ else mkdir -p $GO_BUILD_SUBFOLDER fi -cp -R $1/* $GO_BUILD_SUBFOLDER +cp -R "$1"/* $GO_BUILD_SUBFOLDER # Move to the subfolder cd "$GO_BUILD_SUBFOLDER" 2>/dev/null diff --git a/test_scripts/run_unittests_python.sh b/test_scripts/run_unittests_python.sh index 56bfc5c..aba175f 100755 --- a/test_scripts/run_unittests_python.sh +++ b/test_scripts/run_unittests_python.sh @@ -19,7 +19,7 @@ else exit $UNRECOVERABLE_ERROR_EXIT_CODE fi -PYTHON_BUILD_SUBFOLDER=python_$1 +PYTHON_BUILD_SUBFOLDER=$(dirname "$1")/python_$(basename "$1") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing Python build subfolder: $PYTHON_BUILD_SUBFOLDER\n" @@ -41,7 +41,7 @@ else mkdir -p $PYTHON_BUILD_SUBFOLDER fi -cp -R $1/* $PYTHON_BUILD_SUBFOLDER +cp -R "$1"/* $PYTHON_BUILD_SUBFOLDER # Move to the subfolder cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null diff --git a/test_scripts/run_unittests_react.sh b/test_scripts/run_unittests_react.sh index 514bf15..5360978 100755 --- a/test_scripts/run_unittests_react.sh +++ b/test_scripts/run_unittests_react.sh @@ -17,7 +17,7 @@ if [ -z "$1" ]; then fi # Define the path to the subfolder -NODE_SUBFOLDER=node_$1 +NODE_SUBFOLDER=$(dirname "$1")/node_$(basename "$1") if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then printf "Preparing Node subfolder: $NODE_SUBFOLDER\n" @@ -39,7 +39,7 @@ else mkdir -p $NODE_SUBFOLDER fi -cp -R $1/* $NODE_SUBFOLDER +cp -R "$1"/* $NODE_SUBFOLDER # Move to the subfolder cd "$NODE_SUBFOLDER" 2>/dev/null