add exit code for run_commit_tests

This commit is contained in:
bobo.yang 2023-12-14 10:28:08 +08:00
parent 2b76a11399
commit aee87ad495
3 changed files with 20 additions and 3 deletions

View File

@ -40,9 +40,6 @@ jobs:
git config --global user.email "tester@merico.dev"
git config --global user.name "tester"
python3 test/workflows/workflow_test.py
- run:
name: Run non-existent test script
command: python3 test/not_exist.py
publish:
executor: node-executor
steps:

View File

@ -174,6 +174,9 @@ def git_repo_case(git_url, expected_commit_message):
current_directory = ''
code_diff = ''
def title():
return f'commit {git_url}'
def input_mock(output):
nonlocal stdout_result
nonlocal ui_processed
@ -259,6 +262,9 @@ def case1():
current_input_index = 0
last_commit_id = None
def title():
return 'commit local repo'
def input_mock(output):
nonlocal current_input_index
nonlocal input_pattern

View File

@ -61,6 +61,7 @@ def run_devchat_command(model, commit_command, input_mock):
def run_commit_tests():
model = 'gpt-4-1106-preview' # 替换为实际的模型名称
case_results = []
for case in commit_cases.get_cases():
case_result = False
exit_code = -1
@ -69,8 +70,21 @@ def run_commit_tests():
exit_code = run_devchat_command(model, case['input'], case['input_mock'])
case_result = case['assert']()
case['teardown']()
case_results.append((case['title'](), case_result and exit_code == 0))
else:
print('Error: test case setup failed!')
case_results.append((case['title'](), 'Error: test case setup failed!'))
print('Case result:', case_result, ' Exit code:', exit_code)
print('All case results:')
is_error = False
for case_result in case_results:
print(case_result[0], case_result[1])
if case_result[1] != True:
is_error = True
if is_error:
sys.exit(-1)
else:
sys.exit(0)
run_commit_tests()