diff --git a/.gitignore b/.gitignore index fd0e3de..3649d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ schemas.json *_metrics.json *_recommendations.json *_schemas.json +*.log \ No newline at end of file diff --git a/tests/test_all_pack.sh b/tests/test_all_pack.sh index 336d20c..e5f82eb 100755 --- a/tests/test_all_pack.sh +++ b/tests/test_all_pack.sh @@ -35,36 +35,50 @@ generate_test_packs "${ROOT_DIR}" # Call the function to generate the TEST_DATASETS array generate_test_datasets "${DATA_DIR}" +current_datetime=$(date +"%Y%m%d") + # Iterate over each dataset for dataset in "${TEST_DATASETS[@]}"; do # For each dataset, iterate over each test pack for pack in "${TEST_PACKS[@]}"; do - echo "Processing Dataset: ${dataset} with Test Pack: ${pack}" + mkdir -p "${DATA_DIR}/${dataset}/output/${current_datetime}" + log_file="${DATA_DIR}/${dataset}/output/${current_datetime}/${dataset}_${pack}.log" + # Redirect the outputs of this iteration to the log file + { + echo "Processing Dataset: ${dataset} with Test Pack: ${pack}" - # 1. Copy source_conf.json from the dataset directory into the current test pack directory - cp "${DATA_DIR}/${dataset}/source_conf.json" "${ROOT_DIR}/${pack}" + # 1. Copy source_conf.json from the dataset directory into the current test pack directory + cp "${DATA_DIR}/${dataset}/source_conf.json" "${ROOT_DIR}/${pack}" - # 2. Change to the test pack directory - cd "${ROOT_DIR}/${pack}" + # 2. Change to the test pack directory + cd "${ROOT_DIR}/${pack}" - # 3. Execute the run.sh script - if [ -x "./run.sh" ]; then - ./run.sh - else - echo "run.sh is not executable or not found in $pack. Skipping." - continue - fi + # 3. Execute the run.sh script + if [ -x "./run.sh" ]; then + ./run.sh + else + echo "run.sh is not executable or not found in $pack. Skipping." + continue + fi + + # 4. Once processing is done, copy the result files back into the dataset directory + cp metrics.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_metrics.json" + cp recommendations.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_recommendations.json" + cp schemas.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_schemas.json" + cp *.html "${DATA_DIR}/${dataset}/output/${current_datetime}/" + cp *.xlsx "${DATA_DIR}/${dataset}/output/${current_datetime}/" + cp *.csv "${DATA_DIR}/${dataset}/output/${current_datetime}/" - # 4. Once processing is done, copy the result files back into the dataset directory - cp metrics.json "${DATA_DIR}/${dataset}/${pack}_metrics.json" - cp recommendations.json "${DATA_DIR}/${dataset}/${pack}_recommendations.json" - cp schemas.json "${DATA_DIR}/${dataset}/${pack}_schemas.json" + # 6. Cleanup + # Remove all .json files except pack_conf.json + find "${ROOT_DIR}/${pack}/" -type f -name "*.json" ! -name "pack_conf.json" -exec rm {} + - # 5. Print a completion message (optional) - echo "Completed: ${dataset} with ${pack}" + # Remove all .html files + find "${ROOT_DIR}/${pack}/" -type f -name "*.html" -exec rm {} + - # 6. Cleanup - rm "${ROOT_DIR}/${pack}/source_conf.json" "${ROOT_DIR}/${pack}/metrics.json" "${ROOT_DIR}/${pack}/recommendations.json" "${ROOT_DIR}/${pack}/schemas.json" || echo "Error removing source_conf.json from $pack" + echo "Completed: ${dataset} with ${pack}" + echo "Cleanup done for $pack." + } &> "${log_file}" # Return to the root directory for the next iteration cd "${ROOT_DIR}" diff --git a/tests/test_one_pack.sh b/tests/test_one_pack.sh index 4ad2032..810ac4c 100644 --- a/tests/test_one_pack.sh +++ b/tests/test_one_pack.sh @@ -12,35 +12,57 @@ generate_test_datasets() { done } +current_datetime=$(date +"%Y%m%d") + process_data_pack() { local dataset="$1" local pack="$2" - echo "Processing Dataset: ${dataset} with Test Pack: ${pack}" + # Define log file path + mkdir -p "${DATA_DIR}/${dataset}/output/${current_datetime}" + log_file="${DATA_DIR}/${dataset}/output/${current_datetime}/${dataset}_${pack}.log" + # Redirect the outputs of this iteration to the log file + { + echo "Processing Dataset: ${dataset} with Test Pack: ${pack}" + + # 1. Copy source_conf.json from the dataset directory into the current test pack directory + cp "${DATA_DIR}/${dataset}/source_conf.json" "${ROOT_DIR}/${pack}" + + # 2. Change to the test pack directory + cd "${ROOT_DIR}/${pack}" || return + + # 3. Execute the run.sh script + if [ -x "./run.sh" ]; then + ./run.sh + else + echo "run.sh is not executable or not found in $pack. Skipping." + return + fi + + # 4. Once processing is done, copy the result files back into the dataset directory + cp metrics.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_metrics.json" + cp recommendations.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_recommendations.json" + cp schemas.json "${DATA_DIR}/${dataset}/output/${current_datetime}/${pack}_schemas.json" + cp *.html "${DATA_DIR}/${dataset}/output/${current_datetime}/" + cp *.xlsx "${DATA_DIR}/${dataset}/output/${current_datetime}/" + cp *.csv "${DATA_DIR}/${dataset}/output/${current_datetime}/" - # 1. Copy source_conf.json from the dataset directory into the current test pack directory - cp "${DATA_DIR}/${dataset}/source_conf.json" "${ROOT_DIR}/${pack}" - # 2. Change to the test pack directory - cd "${ROOT_DIR}/${pack}" || return + # 5. Print a completion message + echo "Completed: ${dataset} with ${pack}" - # 3. Execute the run.sh script - if [ -x "./run.sh" ]; then - ./run.sh - else - echo "run.sh is not executable or not found in $pack. Skipping." - return - fi + # 6. Cleanup + # Remove all .json files except pack_conf.json + find "${ROOT_DIR}/${pack}/" -type f -name "*.json" ! -name "pack_conf.json" -exec rm {} + - # 4. Once processing is done, copy the result files back into the dataset directory - cp metrics.json "${DATA_DIR}/${dataset}/${pack}_metrics.json" - cp recommendations.json "${DATA_DIR}/${dataset}/${pack}_recommendations.json" - cp schemas.json "${DATA_DIR}/${dataset}/${pack}_schemas.json" + # Remove all .html files + find "${ROOT_DIR}/${pack}/" -type f -name "*.html" -exec rm {} + - # 5. Print a completion message - echo "Completed: ${dataset} with ${pack}" + # Print a message shortly after cleanup process. This is optional. + echo "Cleanup done for $pack." + } &> "${log_file}" - # 6. Cleanup - rm "${ROOT_DIR}/${pack}/source_conf.json" "${ROOT_DIR}/${pack}/metrics.json" "${ROOT_DIR}/${pack}/recommendations.json" "${ROOT_DIR}/${pack}/schemas.json" || echo "Error removing files from $pack" + # Return to the root directory for the next iteration + cd "${ROOT_DIR}" } if [ "$#" -lt 1 ]; then