提交 c01b50be 创建 作者: 305350171@qq.com's avatar 305350171@qq.com

提交作业

上级 9065b0bc
流水线 #154125 已通过 于阶段
用时 42 秒
*.exe
*.o
*.bak
*.out
*.html
user_output*.txt
# 不要删除或更改此文件
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_program:latest"
stages:
- case1
- code-analysis
variables:
TEACHERCHECK_REPO: "engintime/cpp-lab/teachers-packet/cpp-language/Lab107.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
- intranet
.codecode-analysis-runner: &codecode-analysis-runner
tags:
- ubuntu-16.04
- short-job
- code-analysis
- intranet
case1:
stage: case1
<<: *codecode-runner
script:
- python3 .vscode/test.py ci
only:
- master
teacher-check1:
stage: case1
<<: *codecode-runner
script:
- make
- count=$(find . -name "input*.txt" | wc -l)
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/.vscode/test.py .vscode/test.py -b -B -y -i --suppress-common-lines
- for i in $(seq 1 1 $count);
do
./app.exe < input${i}.txt > /dev/null;
echo "正在检查input${i}.txt文件的一致性";
diff template/input${i}.txt input${i}.txt -b -B -y -i --suppress-common-lines;
echo "正在检查output${i}.txt文件的一致性";
diff template/output${i}.txt output${i}.txt -b -B -y -i --suppress-common-lines;
done
- fileidentity.sh
- if [ -n "$TEACHERCHECK_REPO" ];
then
git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check;
extracount=$(cd teacher_check && find . -name "input*.txt" | wc -l);
for i in $(seq 1 1 $extracount);
do
echo "正在检查附加算例case${i}";
./app.exe < teacher_check/input${i}.txt > user_output${i}.txt;
diff teacher_check/output${i}.txt user_output${i}.txt -b -B -y -i -W 100;
done
source extracase.sh;
fi;
only:
- master
when: manual
allow_failure: true
code-analysis:
stage: code-analysis
<<: *codecode-analysis-runner
script:
- make
- ./app.exe < input1.txt > /dev/null
- mkdir -p build
- cppcheck -v --force --enable=all --xml -I./ ./ 2> ./build/cppcheck-report.xml
- bash -c 'find ./ -regex ".*\.c\|.*\.h" | vera++ -S -s -d -c ./build/vera-report.xml'
- valgrind --xml=yes --xml-file=./build/valgrind-report.xml ./app.exe < input1.txt > /dev/null
- sonar-scanner -Dsonar.projectKey=ProjectKey-$CI_PROJECT_ID -Dsonar.projectName=$CI_PROJECT_NAME -Dsonar.links.homepage=$CI_PROJECT_URL -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.url=$CODECODE_PROTOCOL$CODECODE_DOMAIN
allow_failure: true
only:
- master
#!/bin/env python
# -*- coding: utf-8 -*-
import sys
import argparse
import os
import filecmp
import subprocess
import platform
print(
"************************************************************\n"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,\n"
"说明 python 运行环境中缺少必要的包。\n"
"此时可以启动\"安装python包\"任务来修复 python 运行环境(需要连接互联网)。\n"
"************************************************************\n"
)
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
if __name__ == "__main__":
print("gitpush.py version: 1.0")
execResult = os.system("git config credential.helper \"\" && git add . && git commit -m \"提交作业\"")
if execResult == 256 or execResult == 1:
print("\n-------- 本次提交没有任何变更,即使推送成功,也不代表远程一定有提交记录 --------")
print("-------- 请对项目中的文件进行修改后再进行提交-----------------------------------")
elif execResult != 0:
print(Fore.RED + "\n-------- 提交作业失败! 错误码: {0}--------".format(execResult), file = stream)
print(Fore.WHITE, file = stream)
exit(0)
print("\n-------------------------------------------------------------------------------")
print("请在 VSCode 顶部弹出的命令面板中输入 Git 远程库的用户名和密码。通常为 CodeCode 平台的用户名和密码。")
print("-------------------------------------------------------------------------------")
execResult = os.system("git push")
if execResult == 0:
print(Fore.GREEN + "\n-------- 提交作业成功! --------", file = stream)
print(Fore.WHITE, file = stream)
else:
print(Fore.RED + "\n--- 提交作业失败! 想解决失败问题? 使用浏览器访问下面链接即可。 ---", file = stream)
print(Fore.RED + "https://www.codecode.net/engintime/codecode/publicmanual/blob/master/GitFAQ.md", file = stream)
print(Fore.WHITE, file = stream)
\ No newline at end of file
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app.exe",
"args": [],
"stopAtEntry": false,
"preLaunchTask": "make",
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "生成项目(make)",
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
]
}
]
}
}
\ No newline at end of file
{
"files.exclude": {
"**/*.git*": true,
"**/sonar*": true,
"**/valgrind-report.out": true,
"**/requirements.txt": true,
},
"files.associations": {
"stdio.h": "c"
}
}
\ No newline at end of file
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make",
"label": "生成项目(make)",
"type": "shell",
"command": "make",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目 ; make"
},
"linux": {
"command": "echo 正在使用makefile文件生成项目 && make && echo 生成项目成功"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"focus": true,
"group": "make"
},
"problemMatcher": "$gcc"
},
{
"label": "安装python包",
"type": "shell",
"windows": {
"command": "pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"linux": {
"command": "pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "silent"
"reveal": "always",
"group": "setup_pip_package"
},
"problemMatcher": "$msCompile"
"problemMatcher": "$gcc"
},
{
"label": "lacal_test_cpp",
"label": "测试(test)",
"type": "shell",
"command": "python ${workspaceFolder}/local_test_c.py",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\test.py"
},
"linux": {
"command": "python3 .vscode/test.py"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "test"
},
"problemMatcher": "$gcc"
},
{
"label": "清理项目(make clean)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件清理项目 ; make clean"
},
"linux": {
"command": "echo 正在使用makefile文件清理项目 && make clean && echo 清理项目成功"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "silent"
"reveal": "always",
"group": "clean"
},
"problemMatcher": "$msCompile"
"problemMatcher": "$gcc"
},
{
"label": "make_clean_windows",
"label": "提交作业(git push)",
"type": "shell",
"command": "make clean_win",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\gitpush.py"
},
"linux": {
"command": "python3 .vscode/gitpush.py"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "silent"
"reveal": "always",
"group": "git-push"
},
"problemMatcher": "$msCompile"
"problemMatcher": "$gcc"
},
{
"label": "make_clean_linux",
"label": "内存检测",
"type": "shell",
"command": "make clean_linux",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用Dr.Memory检测内存 ; make ; cmd.exe /c \"drmemory -ignore_kernel -leaks_only -brief -batch -- .\\app.exe '<' input1.txt\""
},
"linux": {
"command": "echo 正在使用 Valgrind 检测内存 && make && echo ***如果提示 /bin/bash: valgrind: command not found 可使用终端命令 sudo apt install valgrind 安装(需要连接互联网)*** && valgrind --leak-check=full ./app.exe < input1.txt"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "silent"
"reveal": "always",
"group": "test"
},
"problemMatcher": "$msCompile"
}
"problemMatcher": "$gcc"
}
]
}
}
\ No newline at end of file
......@@ -10,13 +10,27 @@ import filecmp
import subprocess
import platform
# 使用此文件的目录作为当前工作目录
os.chdir(os.path.dirname(__file__))
bIncludeCi = False
if len(sys.argv) > 1 and sys.argv[1] == "ci":
bIncludeCi = True
if bIncludeCi == False:
print(
"************************************************************\n"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,\n"
"说明 python 运行环境中缺少必要的包。\n"
"此时可以启动\"安装python包\"任务来修复 python 运行环境(需要连接互联网)。\n"
"************************************************************\n"
)
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
red = lambda text: '\033[0;31;1m' + text + '\033[0m'
green = lambda text: '\033[0;32;1m' + text + '\033[0m'
yellow = lambda text: '\033[0;33;1m' + text + '\033[0m'
# 读取文件
def read_file(file_name):
try:
......@@ -29,6 +43,8 @@ def read_file(file_name):
print('Read input file Error: {0}'.format(error))
sys.exit()
# 比较时忽略行末的空格和文件末尾的回车换行
def advanced_file_compare(file1, file2):
f1 = open(file1)
......@@ -66,86 +82,167 @@ def advanced_file_compare(file1, file2):
return returnVal
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum):
def compare_file(file1, file2, seqNum, caseCount, bIncludeCi):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
print("正在比较文件 {0} 和 {1}".format(file1, file2), end=': ')
# if os.path.isfile(file1) and os.path.isfile(file2) and filecmp.cmp(file1, file2):
print("正在比较标准答案输出文件 {0} 和用户编写的应用程序输出文件 {1}".format(file1, file2), end=': ')
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
print(Fore.GREEN + "Case{0} 验证成功".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
score = 40
if seqNum == caseCount:
score = 100
else:
score = score + 60 / caseCount * seqNum
if bIncludeCi :
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 1)
print("exec-score", int(score))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bIncludeCi, promptInfo, 1)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
outputPromptInfo(bIncludeCi, promptInfo, 1)
returnVal = 1
return returnVal
else:
print("文件不同")
print(Fore.RED + "Case{0} 验证失败".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
promptInfo = "Case{0} 验证失败".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 2)
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
promptContent = "<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>".format(seqNum)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
if bIncludeCi == False:
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
promptContent = "<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>".format(seqNum)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
return returnVal
else:
return returnVal
if __name__ == "__main__":
print()
print(Fore.YELLOW + "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。", file = stream)
print(Fore.WHITE, file = stream)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
execResult = os.system("python --version")
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
# 1表示绿色,2表示红色,3表示黄色
def outputPromptInfo(bIncludeCi, promptInfo, color):
if bIncludeCi :
if color == 1:
print(green(promptInfo))
elif color == 2:
print(red(promptInfo))
elif color == 3:
print(yellow(promptInfo))
else:
print(promptInfo)
else:
if color == 1:
print(Fore.GREEN + promptInfo, file = stream)
elif color == 2:
print(Fore.RED + promptInfo, file = stream)
elif color == 3:
print(Fore.YELLOW + promptInfo, file = stream)
else:
print(promptInfo)
print(Fore.WHITE, file = stream)
exit(1)
print()
sys.stdout.flush()
if __name__ == "__main__":
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
promptInfo = "正在使用 makefile 文件生成项目"
outputPromptInfo(bIncludeCi, promptInfo, 1)
execResult = os.system("make")
if execResult != 0:
errorInfo = "生成项目失败"
outputPromptInfo(bIncludeCi, errorInfo, 2)
exit(1)
else:
score = 40
if not os.path.isfile("output1.txt"):
score = 100
if bIncludeCi:
promptInfo = "生成项目成功"
outputPromptInfo(bIncludeCi, promptInfo, 1)
promptInfo = "exec-score {0}".format(score)
print(promptInfo)
else:
promptInfo = "生成项目成功, 分数 {0}".format(score)
outputPromptInfo(bIncludeCi, promptInfo, 1)
# 获取case的数量
caseCount = 1
while 1:
outputFile = "output{0}.txt".format(caseCount)
if not os.path.isfile(outputFile):
caseCount -= 1
break
caseCount += 1
seqNum = 1
while 1:
inputFile = "input{0}.txt".format(seqNum)
outputFile = "output{0}.txt".format(seqNum)
useroutputFile = "user_output{0}.txt".format(seqNum)
if seqNum == 1 and not os.path.isfile(outputFile):
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
promptInfo = "该项目未提供自动化验证功能"
if bIncludeCi :
print(red(promptInfo))
else:
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(outputFile):
break
print("正在使用文件 {0} 验证 case{1}".format(inputFile, seqNum))
runCommand = "make && app.exe < {0} > {1}".format(inputFile, useroutputFile)
runCommand = "./app.exe < {0} > {1}".format(inputFile, useroutputFile)
if platform.system().lower() == 'windows':
runCommand = "app.exe < {0} > {1}".format(inputFile, useroutputFile)
promptInfo = "执行的命令是: {0}".format(runCommand)
outputPromptInfo(bIncludeCi, promptInfo, 0)
if bIncludeCi == False:
promptInfo = "提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
outputPromptInfo(bIncludeCi, promptInfo, 3)
execResult = os.system(runCommand)
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
break
errorInfo = "应用程序执行异常,返回值:{0}。".format(execResult)
outputPromptInfo(bIncludeCi, errorInfo, 2)
exit(1)
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum) == 0:
print("正在使用浏览器打开文件比较结果,可帮助用户查找验证失败的原因。")
# 使用浏览器打开比较结果页面
print(os.path.realpath(compResultFile))
webbrowser.open('file://' + os.path.realpath(compResultFile))
break
if compare_file(outputFile, useroutputFile, seqNum, caseCount, bIncludeCi) == 0:
if bIncludeCi :
print("使用的标准输入文件是 intput{0}.txt。\n标准答案输出文件 output{1}.txt(左边)与用户编写的应用程序输出文件 user_output{2}.txt(右边)的比较结果:".format(seqNum, seqNum, seqNum))
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(outputFile, useroutputFile)
execResult = os.system(runCommand)
else:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
outputPromptInfo(bIncludeCi, promptInfo, 2)
exit(1)
seqNum = seqNum + 1
\ No newline at end of file
a=input();
x = eval(a);
if(x < 1):
y = x;
result = "x = {}, y = x = {}".format(x, y)
elif(x < 10):
y = 2 * x - 1;
result = "x = {}, y = 2 * x - 1 = {}".format(x, y)
else:
y = 3 * x - 11;
result = "x = {}, y = 3 * x - 11 = {}".format(x, y)
print (result);
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
# 使用此文件的目录作为当前工作目录
os.chdir(os.path.dirname(__file__))
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
# 读取文件
def read_file(file_name):
try:
file_desc = open(file_name, 'r')
# 读取后按行分割
text = file_desc.read().splitlines()
file_desc.close()
return text
except IOError as error:
print('Read input file Error: {0}'.format(error))
sys.exit()
# 比较时忽略行末的空格和文件末尾的回车换行
def advanced_file_compare(file1, file2):
f1 = open(file1)
f2 = open(file2)
returnVal = 1
str1 = []
for line1 in f1:
line1 = line1.rstrip()
line1 = line1.replace('\n', '')
if len(line1) != 0:
str1.append(line1)
str2 = []
for line2 in f2:
line2 = line2.rstrip()
line2 = line2.replace('\n', '')
if len(line2) != 0:
str2.append(line2)
count = 0
if len(str1) == len(str2):
for line1 in str1:
if line1 != str2[count]: #文件不同
returnVal = 0
break
else:
count = count + 1
else:
returnVal = 0
f1.close()
f2.close()
return returnVal
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
print("正在比较文件 {0} 和 {1}".format(file1, file2), end=': ')
# if os.path.isfile(file1) and os.path.isfile(file2) and filecmp.cmp(file1, file2):
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
print(Fore.GREEN + "Case{0} 验证成功".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
returnVal = 1
return returnVal
else:
print("文件不同")
print(Fore.RED + "Case{0} 验证失败".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
promptContent = "<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>".format(seqNum)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
return returnVal
if __name__ == "__main__":
print()
print(Fore.YELLOW + "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。", file = stream)
print(Fore.WHITE, file = stream)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
execResult = os.system("python3 --version")
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
exit(1)
print()
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
seqNum = 1
while 1:
inputFile = "input{0}.txt".format(seqNum)
outputFile = "output{0}.txt".format(seqNum)
useroutputFile = "user_output{0}.txt".format(seqNum)
if seqNum == 1 and not os.path.isfile(outputFile):
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(outputFile):
break
print("正在使用文件 {0} 验证 case{1}".format(inputFile, seqNum))
runCommand = "python3 app.py < {0} > {1}".format(inputFile, useroutputFile)
execResult = os.system(runCommand)
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
break
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum) == 0:
print("正在使用浏览器打开文件比较结果,可帮助用户查找验证失败的原因。")
# 使用浏览器打开比较结果页面
webbrowser.open('file://' + os.path.realpath(compResultFile))
break
seqNum = seqNum + 1
\ No newline at end of file
......@@ -5,6 +5,7 @@ using namespace std;
int main()
{
int x = 0, y = 0;
int *z = new int;
  • Developer

    4 bytes in 1 blocks are definitely lost in loss record 1 of 2

    0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 0x400A05: main (main.cpp:8) 📘
    🔽 Variable 'z' is allocated memory that is never used. 📘

Please register or sign in to reply
cin >> x;
if ( x < 1 )
{
......
......@@ -14,13 +14,22 @@ CC = g++
CFLAGS = -g -w -fmax-errors=10 -std=c++11 -fsigned-char -I${DIR_INC}
${BIN_TARGET}:${OBJ}
@echo --- build executable file: $@
$(CC) $(OBJ) -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp
@echo --- build object file: $@
$(CC) $(CFLAGS) -c $< -o $@
clean_win:
del *.o *.exe
RM = @echo 无法识别的平台。无法删除文件
clean_linux:
rm *.o *.exe
\ No newline at end of file
ifdef OS
RM = del /Q
else
ifeq ($(shell uname), Linux)
RM = rm -f
endif
endif
clean:
$(RM) *.exe *.o result_comparation.html user_output*
\ No newline at end of file
x = -1, y = x = -5
\ No newline at end of file
x = -1, y = x = -1
\ No newline at end of file
# -*- coding: utf-8 -*-
###### 不要列出标准库中已包含的包,例如:Math,time等,如果列出将出现如下错误:######
###### RuntimeError: Package '**' must not be downloaded from pypi ######
colorama
\ No newline at end of file
# 不要删除或修改此文件
# required metadata
sonar.language=c++
# path to source directories (required)
sonar.sources=./
# path to the build artifact
sonar.artifact.path=build/app
# paths to the reports
sonar.cxx.cppcheck.reportPath=./build/cppcheck-report.xml
#sonar.cxx.pclint.reportPath=./build/pclint-report.xml
#sonar.cxx.coverage.reportPath=./build/gcovr-report*.xml
#sonar.cxx.coverage.itReportPath=./build/gcovr-report*.xml
#sonar.cxx.coverage.overallReportPath=./build/gcovr-report*.xml
sonar.cxx.valgrind.reportPath=./build/valgrind-report.xml
sonar.cxx.vera.reportPath=./build/vera-report.xml
#sonar.cxx.rats.reportPath=./build/rats-report.xml
#sonar.cxx.xunit.reportPath=./build/xunit-report.xml
#sonar.cxx.drmemory.reportPath=./build/drmemory-logs/**/results.txt
sonar.cxx.includeDirectories=/usr/include/,/usr/include/linux,/usr/include/x86_64-linux-gnu/bits,/usr/include/x86_64-linux-gnu/sys,/usr/include/c++/5/tr1,./
  • Developer

    代码质量分析发现了 4 个问题。

    • 0 blocker
    • 🚫 0 critical
    • 2 major
    • 🔽 2 minor
    • 0 info

    2 个问题使用代码行评论的方式进行报告,请在此次变更的代码行中审阅这些问题。

    2 个额外的问题

    注意: 存在下列问题的代码行在本次提交中没有发生变更,无法使用代码行评论的方式进行报告。所以将下列问题汇总显示在这里(点击问题链接可以转到对应的源代码行):

    1. Memory leak: z 📘
    2. 🔽 Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project's include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config. (ProjectKey-169407) 📘
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论