From 51c55ef6b5d0796eabc9ed04f9be0b002791ed04 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Wed, 5 Jul 2023 16:31:24 +0000 Subject: [PATCH] update --- examples/run_all.sh | 6 +++--- tests/extract_errors.py | 14 ++++++++++++++ tests/run_all.sh | 15 ++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 tests/extract_errors.py diff --git a/examples/run_all.sh b/examples/run_all.sh index 39894cdd0..45f9af6d3 100644 --- a/examples/run_all.sh +++ b/examples/run_all.sh @@ -6,9 +6,9 @@ for file in ./*.py; do # 检查文件是否为 Python 文件 if [ -f "$file" ]; then if [[ -n "$GITHUB_ACTIONS" ]]; then - echo ::group::example Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file + echo ::group::example Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file else - echo Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file + echo Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file fi # 执行文件 python "$file" @@ -17,7 +17,7 @@ for file in ./*.py; do exit 1 fi if [[ -n "$GITHUB_ACTIONS" ]]; then - echo "::endgroup::" + echo "::endgroup::" fi fi done diff --git a/tests/extract_errors.py b/tests/extract_errors.py new file mode 100644 index 000000000..efa8521e6 --- /dev/null +++ b/tests/extract_errors.py @@ -0,0 +1,14 @@ +import re +import sys + +error_msg = sys.stdin.read() + +pattern = r'File "?(.*?)"?, line (\d+),.*\n(.*?)\n(.*?)$' +match = re.search(pattern, error_msg, re.MULTILINE) +if match: + file = match.group(1) + line = match.group(2) + error_info = match.group(4) + # error_info = match.group(3) + '\n' + match.group(4) + output = f"::error file={file},line={line}::{error_info}" + print(output) diff --git a/tests/run_all.sh b/tests/run_all.sh index 20b33de29..304a15a98 100644 --- a/tests/run_all.sh +++ b/tests/run_all.sh @@ -8,18 +8,23 @@ for file in ./test_*.py; do # 检查文件是否为 Python 文件 if [ -f "$file" ]; then if [[ -n "$GITHUB_ACTIONS" ]]; then - echo ::group::Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file + echo ::group::Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file else - echo Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file + echo Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file fi # 执行文件 - python "$file" 2> >(grep "File <$file>, line") + python_output=$(python $file 2>&1) + if [ $? -ne 0 ]; then echo "run $file failed" failed_tests+=("$file") + if [[ -n "$GITHUB_ACTIONS" ]]; then + echo $python_output | python ./tests/extract_errors.py + fi + echo $python_output fi if [[ -n "$GITHUB_ACTIONS" ]]; then - echo "::endgroup::" + echo "::endgroup::" fi fi done @@ -28,6 +33,6 @@ if [ ${#failed_tests[@]} -ne 0 ]; then echo "failed tests file:" for failed_test in "${failed_tests[@]}"; do echo "$failed_test" - echo "::error file=$failed_test,line=1,col=5,endColumn=7::Missing semicolon" done + exit 1 fi