Skip to content

Commit e4f10c3

Browse files
committed
tests: unwrap to know where goes wrong
1 parent f74215f commit e4f10c3

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

src/diff.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{BoxStr, ProofKind, Result, SerFunction};
1+
use crate::{BoxStr, ProofKind, SerFunction};
22
use indexmap::{IndexMap, IndexSet};
33
use serde::{Deserialize, Serialize};
44
use std::{
@@ -51,7 +51,7 @@ impl KaniListHarnesses {
5151
self.inner = inner;
5252
}
5353

54-
pub fn strip_path_prefix(&mut self, prefix: &str) -> Result<()> {
54+
pub fn strip_path_prefix(&mut self, prefix: &str) {
5555
let mut map = IndexMap::with_capacity(self.inner.len());
5656
for (key, val) in self.inner.iter_mut() {
5757
let val = std::mem::take(val);
@@ -69,7 +69,6 @@ impl KaniListHarnesses {
6969
}
7070
map.sort_unstable_keys();
7171
self.inner = map;
72-
Ok(())
7372
}
7473

7574
pub fn strip_path_closure_name(&mut self, v_text: &[&str]) {
@@ -147,20 +146,21 @@ impl KaniListJson {
147146
}
148147

149148
// FIXME: merge this and the raw one.
150-
pub fn strip_path_prefix<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
151-
let path = path.as_ref().canonicalize()?;
149+
pub fn strip_path_prefix<P: AsRef<Path>>(&mut self, path: P) {
150+
let path = path.as_ref();
151+
let path = path
152+
.canonicalize()
153+
.unwrap_or_else(|err| panic!("Unable to canonicalize {path:?}:\n{err}"));
152154
let prefix = &format!("{}{MAIN_SEPARATOR}", path.to_str().unwrap());
153155

154-
self.standard_harnesses.strip_path_prefix(prefix)?;
155-
self.contract_harnesses.strip_path_prefix(prefix)?;
156-
Ok(())
156+
self.standard_harnesses.strip_path_prefix(prefix);
157+
self.contract_harnesses.strip_path_prefix(prefix);
157158
}
158159

159160
/// This function is used in tests.
160-
pub fn strip_path_prefix_raw(&mut self, prefix: &str) -> Result<()> {
161-
self.standard_harnesses.strip_path_prefix(prefix)?;
162-
self.contract_harnesses.strip_path_prefix(prefix)?;
163-
Ok(())
161+
pub fn strip_path_prefix_raw(&mut self, prefix: &str) {
162+
self.standard_harnesses.strip_path_prefix(prefix);
163+
self.contract_harnesses.strip_path_prefix(prefix);
164164
}
165165

166166
pub fn strip_path_closure_name(&mut self, text: &[&str]) {

tests/kani_list.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ fn validate_kani_list_json() -> Result<()> {
3737
Ok(())
3838
}
3939

40-
fn read_kani_list_json() -> Result<KaniListJson> {
40+
fn read_kani_list_json() -> KaniListJson {
4141
const KANI_LIST_JSON: &str = "assets/kani-list_verify-rust-std.json";
4242
const PREFIX: &str = "/home/gh-zjp-CN/distributed-verification/verify-rust-std/library/";
4343

44-
let mut kani_list: KaniListJson = read_file(KANI_LIST_JSON)?;
45-
kani_list.strip_path_prefix_raw(PREFIX)?;
46-
Ok(kani_list)
44+
let mut kani_list: KaniListJson = read_file(KANI_LIST_JSON).unwrap();
45+
kani_list.strip_path_prefix_raw(PREFIX);
46+
kani_list
4747
}
4848

4949
#[test]
50-
fn kani_list_json() -> Result<()> {
51-
let kani_list = read_kani_list_json()?;
50+
fn kani_list_json() {
51+
let kani_list = read_kani_list_json();
5252

5353
expect_file!["snapshots/kani_list/kani_list_json-files.json"]
54-
.assert_eq(&serde_json::to_string_pretty(&kani_list.files())?);
54+
.assert_eq(&serde_json::to_string_pretty(&kani_list.files()).unwrap());
5555

5656
expect![[r#"
5757
Totals {
@@ -61,6 +61,4 @@ fn kani_list_json() -> Result<()> {
6161
}
6262
"#]]
6363
.assert_debug_eq(&kani_list.totals);
64-
65-
Ok(())
6664
}

tests/verify-rust-std.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ const PREFIX_LOCAL_DIR: &str = "/home/gh-zjp-CN/distributed-verification/";
88
const PREFIX_CI_DIR: &str = "/home/runner/work/distributed-verification/distributed-verification/";
99

1010
/// Read kani-list.json generated from verify-rust-std CI.
11-
fn read_kani_list_json() -> Result<KaniListJson> {
11+
fn read_kani_list_json() -> KaniListJson {
1212
const KANI_LIST_JSON: &str = "tmp/ubuntu-latest-kani-list.json/kani-list.json";
1313
const PREFIX: &str = "/home/runner/work/verify-rust-std/verify-rust-std/library/";
1414

15-
let mut kani_list: KaniListJson = read_file(KANI_LIST_JSON)?;
15+
let mut kani_list: KaniListJson = read_file(KANI_LIST_JSON).unwrap();
1616
kani_list.normalize_file_path();
17-
kani_list.strip_path_prefix_raw(PREFIX)?;
17+
kani_list.strip_path_prefix_raw(PREFIX);
1818
kani_list.strip_path_closure_name(&[PREFIX, PREFIX_LOCAL_DIR, PREFIX_CI_DIR]);
19-
Ok(kani_list)
19+
kani_list
2020
}
2121

22-
fn read_core_json() -> Result<Vec<SerFunction>> {
22+
fn read_core_json() -> Vec<SerFunction> {
2323
const CORE_JSON: &str = "./assets/core.json";
2424
const PREFIX_LOCAL: &str = "/home/gh-zjp-CN/distributed-verification/verify-rust-std/library/";
2525
const PREFIX_CI: &str = "/home/runner/work/distributed-verification/distributed-verification/verify-rust-std/library/";
2626

27-
let mut v: Vec<SerFunction> = read_file(CORE_JSON)?;
27+
let mut v: Vec<SerFunction> = read_file(CORE_JSON).unwrap();
2828
for func in &mut v {
2929
// strip_path_closure_name
3030
func.name = func
@@ -35,12 +35,12 @@ fn read_core_json() -> Result<Vec<SerFunction>> {
3535
.replace(PREFIX_CI_DIR, "")
3636
.into();
3737
}
38-
Ok(v)
38+
v
3939
}
4040

4141
#[test]
42-
fn core_json() -> Result<()> {
43-
let v_func = read_core_json()?;
42+
fn core_json() {
43+
let v_func = read_core_json();
4444
let merged = MergedHarnesses::new(&v_func);
4545

4646
#[derive(Debug)]
@@ -58,13 +58,11 @@ fn core_json() -> Result<()> {
5858
}
5959
"#]]
6060
.assert_debug_eq(&count);
61-
62-
Ok(())
6361
}
6462

6563
#[test]
66-
fn read() -> Result<()> {
67-
let kani_list = read_kani_list_json()?;
64+
fn read() {
65+
let kani_list = read_kani_list_json();
6866
expect![[r#"
6967
Totals {
7068
standard_harnesses: 8350,
@@ -77,7 +75,7 @@ fn read() -> Result<()> {
7775
let harness_names = kani_list.harness_names(|file, _| file.starts_with("core/"));
7876
expect_file!["snapshots/verify-rust-std/harness_names.txt"].assert_debug_eq(&harness_names);
7977

80-
let v_func = read_core_json()?;
78+
let v_func = read_core_json();
8179
let merged = MergedHarnesses::new(&v_func);
8280

8381
let function_names = merged.function_names(|f| f.file.starts_with("core/"));
@@ -89,6 +87,4 @@ fn read() -> Result<()> {
8987
.collect();
9088
expect_file!["snapshots/verify-rust-std/names_not_in_functions.txt"]
9189
.assert_debug_eq(&names_not_in_functions);
92-
93-
Ok(())
9490
}

0 commit comments

Comments
 (0)