Merge pull request #35 from marco-c/test_coveralls_format

Test coveralls format
This commit is contained in:
Marco 2017-09-11 14:15:43 +02:00 коммит произвёл GitHub
Родитель 60f9f3c956 bf022039e9
Коммит 97b60aaad6
21 изменённых файлов: 625 добавлений и 20 удалений

Просмотреть файл

Просмотреть файл

@ -0,0 +1,35 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
1,
null,
10,
9,
3,
null,
null,
9,
0,
null,
null,
null,
1
],
"name": "main.c",
"source_digest": "8c62b57cb7d17ca440f15f78b9661eae"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,35 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
null,
20,
9,
3,
3,
null,
9,
0,
0,
9,
null,
1
],
"name": "main.c",
"source_digest": "8c62b57cb7d17ca440f15f78b9661eae"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,56 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
1,
1,
1,
null,
2,
2,
null,
null,
0,
0,
0,
null,
null,
null,
null,
null,
1,
null,
2,
null,
1,
1,
null,
1,
0,
null,
null,
1,
3
],
"name": "main.cpp",
"source_digest": "c7ce95fb29a60db473f157d20a203d94"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,56 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
null,
1,
1,
null,
null,
2,
null,
null,
null,
0,
0,
null,
null,
null,
null,
null,
null,
null,
1,
null,
4,
4,
null,
4,
0,
0,
null,
1,
1
],
"name": "main.cpp",
"source_digest": "c7ce95fb29a60db473f157d20a203d94"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,65 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
1,
1,
1,
null,
1,
1,
1,
3
],
"name": "file.cpp",
"source_digest": "74a2a8e2849b4ebf97c08c3da0d83703"
},
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
null,
null,
1,
1,
1
],
"name": "include.h",
"source_digest": "d6261acc27f21cbf7b44654ef8db5be9"
},
{
"coverage": [
null,
null,
1,
null,
2,
null,
1,
2,
null,
1,
3
],
"name": "main.cpp",
"source_digest": "3d6c13992a5a8f14b972702307216222"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,64 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
1,
1,
null,
null,
1,
1
],
"name": "file.cpp",
"source_digest": "74a2a8e2849b4ebf97c08c3da0d83703"
},
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
null,
null,
null,
1,
1
],
"name": "include.h",
"source_digest": "d6261acc27f21cbf7b44654ef8db5be9"
},
{
"coverage": [
null,
null,
null,
null,
1,
null,
4,
1,
null,
1,
2
],
"name": "main.cpp",
"source_digest": "3d6c13992a5a8f14b972702307216222"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,69 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
1,
null,
2,
null,
1,
2,
null,
1,
0,
null,
null,
1,
3
],
"name": "main.cpp",
"source_digest": "d68e8fe54f7c42b3e1cb8bd572ed62a7"
},
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
null,
null,
1,
1,
1
],
"name": "include.h",
"source_digest": "d6261acc27f21cbf7b44654ef8db5be9"
},
{
"coverage": [
null,
null,
1,
1,
1,
null,
1,
1,
1,
3
],
"name": "file.cpp",
"source_digest": "74a2a8e2849b4ebf97c08c3da0d83703"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,68 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
1,
1,
null,
null,
1,
1
],
"name": "file.cpp",
"source_digest": "74a2a8e2849b4ebf97c08c3da0d83703"
},
{
"coverage": [
null,
null,
null,
null,
1,
null,
4,
1,
null,
2,
0,
0,
null,
1,
2
],
"name": "main.cpp",
"source_digest": "d68e8fe54f7c42b3e1cb8bd572ed62a7"
},
{
"coverage": [
null,
null,
null,
null,
null,
2,
null,
null,
null,
null,
1,
1
],
"name": "include.h",
"source_digest": "d6261acc27f21cbf7b44654ef8db5be9"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,52 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
null,
null,
4,
null,
null,
null,
null,
1,
1,
1,
null,
1,
1,
null,
null,
2,
2,
null,
null,
null,
1,
2,
2,
null,
1,
1,
1,
1,
1
],
"name": "main.cpp",
"source_digest": "cbf46fad5833169d3ce5ddb272ca949a"
}
]
}

Просмотреть файл

Просмотреть файл

@ -0,0 +1,52 @@
{
"git": {
"branch": "master",
"head": {
"id": "COMMIT"
}
},
"repo_token": "TOKEN",
"service_job_number": "",
"service_name": "",
"service_number": "",
"source_files": [
{
"coverage": [
null,
null,
null,
null,
null,
4,
null,
null,
null,
null,
null,
1,
1,
null,
null,
1,
null,
null,
null,
2,
null,
null,
null,
null,
2,
1,
null,
4,
2,
1,
1,
2
],
"name": "main.cpp",
"source_digest": "cbf46fad5833169d3ce5ddb272ca949a"
}
]
}

Просмотреть файл

@ -26,24 +26,30 @@ fn run(path: &Path) {
assert!(status.success());
}
fn read_expected(path: &Path, compiler: &str) -> Vec<String> {
let name = format!("expected_{}.txt", compiler);
fn read_expected(path: &Path, compiler: &str, format: &str) -> String {
let name = format!("expected_{}.{}", compiler, format);
let mut f = File::open(path.join(&name)).expect(format!("{} file not found", name).as_str());
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
let mut v = Vec::new();
for line in s.lines() {
v.push(line.to_string());
}
v
s
}
fn run_grcov(path: &Path, llvm: bool) -> Vec<String> {
fn run_grcov(path: &Path, llvm: bool, output_format: &str) -> String {
let mut args: Vec<String> = Vec::new();
args.push("--".to_string());
if llvm {
args.push("--".to_string());
args.push("--llvm".to_string());
}
args.push("-t".to_string());
args.push(output_format.to_string());
if output_format == "coveralls" {
args.push("--token".to_string());
args.push("TOKEN".to_string());
args.push("--commit-sha".to_string());
args.push("COMMIT".to_string());
args.push("-s".to_string());
args.push(path.to_str().unwrap().to_string());
}
let output = Command::new("cargo")
.arg("run")
@ -52,11 +58,7 @@ fn run_grcov(path: &Path, llvm: bool) -> Vec<String> {
.output()
.expect("Failed to run grcov");
let s = String::from_utf8(output.stdout).unwrap();
let mut v = Vec::new();
for line in s.lines() {
v.push(line.to_string());
}
v
s
}
fn make_clean(path: &Path) {
@ -85,14 +87,14 @@ fn check_equal_inner(a: &Value, b: &Value, skip_methods: bool) -> bool {
a["file"]["total_uncovered"] == b["file"]["total_uncovered"]
}
fn check_equal(expected_output: &[String], output: &[String]) {
fn check_equal_ade(expected_output: &String, output: &String) {
let mut expected: Vec<Value> = Vec::new();
for line in expected_output {
for line in expected_output.lines() {
expected.push(serde_json::from_str(line).unwrap());
}
let mut actual: Vec<Value> = Vec::new();
for line in output {
for line in output.lines() {
actual.push(serde_json::from_str(line).unwrap());
}
@ -115,7 +117,56 @@ fn check_equal(expected_output: &[String], output: &[String]) {
assert!(out.is_some(), "Missing {} - Full output: {:?}", exp, output);
}
assert_eq!(expected.len(), actual_len, "Got same number of expected records.")
assert_eq!(expected.len(), actual_len, "Got same number of expected records.");
}
fn check_equal_coveralls(expected_output: &String, output: &String) {
let expected: Value = serde_json::from_str(expected_output).unwrap();
let actual: Value = serde_json::from_str(output).unwrap();
assert_eq!(expected["git"]["branch"], actual["git"]["branch"]);
assert_eq!(expected["git"]["head"]["id"], actual["git"]["head"]["id"]);
assert_eq!(expected["repo_token"], actual["repo_token"]);
assert_eq!(expected["service_job_number"], actual["service_job_number"]);
assert_eq!(expected["service_name"], actual["service_name"]);
assert_eq!(expected["service_number"], actual["service_number"]);
// On CI, don't check line counts, as on different compiler versions they are slightly different.
let skip_line_counts = env::var("CONTINUOUS_INTEGRATION").is_ok();
let actual_source_files = actual["source_files"].as_array().unwrap();
let expected_source_files = expected["source_files"].as_array().unwrap();
for exp in expected_source_files {
let out = actual_source_files.iter().find(|&&ref x| x["name"] == exp["name"]);
assert!(out.is_some(), "Missing {} - Full output: {:?}", exp, output);
let out = out.unwrap();
assert_eq!(exp["name"], out["name"]);
assert_eq!(exp["source_digest"], out["source_digest"], "Got correct digest for {}", exp["name"]);
if !skip_line_counts {
assert_eq!(exp["coverage"], out["coverage"], "Got correct coverage for {}", exp["name"]);
} else {
let expected_coverage = exp["coverage"].as_array().unwrap();
let actual_coverage = out["coverage"].as_array().unwrap();
assert_eq!(expected_coverage.len(), actual_coverage.len(), "Got same number of lines.");
for i in 0..expected_coverage.len() {
if expected_coverage[i].is_null() {
assert!(actual_coverage[i].is_null(), "Got correct coverage at line {} for {}", i, exp["name"]);
} else {
assert_eq!(expected_coverage[i].as_i64().unwrap() > 0, actual_coverage[i].as_i64().unwrap() > 0, "Got correct coverage at line {} for {}", i, exp["name"]);
}
}
}
}
for out in actual_source_files {
let exp = expected_source_files.iter().find(|&&ref x| x["name"] == out["name"]);
assert!(exp.is_some(), "Got unexpected {} - Expected output: {:?}", out, expected_output);
}
assert_eq!(expected_source_files.len(), actual_source_files.len(), "Got same number of source files.");
}
#[test]
@ -131,7 +182,8 @@ fn test_integration() {
println!("GCC");
make(path, "g++");
run(path);
check_equal(&read_expected(path, "gcc"), &run_grcov(path, false));
check_equal_ade(&read_expected(path, "gcc", "ade"), &run_grcov(path, false, "ade"));
check_equal_coveralls(&read_expected(path, "gcc", "coveralls"), &run_grcov(path, false, "coveralls"));
make_clean(path);
// On CI, don't test llvm, as there are problems for now.
@ -141,7 +193,8 @@ fn test_integration() {
make(path, "clang++");
run(path);
if !skip_llvm {
check_equal(&read_expected(path, "llvm"), &run_grcov(path, true));
check_equal_ade(&read_expected(path, "llvm", "ade"), &run_grcov(path, true, "ade"));
check_equal_coveralls(&read_expected(path, "llvm", "coveralls"), &run_grcov(path, true, "coveralls"));
}
make_clean(path);
}