blob: 645eabe16161340d51eec4314f80d78fa1366f9e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/bin/bash
##########################################################################
# File Name : test.sh
# Encoding : utf-8
# Author : We-unite
# Email : weunite1848@gmail.com
# Created Time : 2023-10-06
##########################################################################
# 如果未出现段错误就重定向输出到res.txt,否则输出到err.txt,并在屏幕上显示出错的年份
# 设置要测试的可执行文件
executable="main"
echo "" > res.txt
start_time=$(date +%s)
for year in {1800..2200}; do
echo "==================测试年份 $year====================="
output=$(./$executable "$year" 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo -e "$year:\n$output" >> res.txt
else
# 执行异常,将错误信息重定向到err.txt
echo -e "$year:\n$output" >> err.txt
echo "执行异常(退出码: $exit_code)"
exit 1
fi
done
end_time=$(date +%s)
echo "测试成功!"
echo "总用时:$((end_time - start_time))秒"
|