Skip to content

Commit 7ff2e7f

Browse files
committed
Merge rust-bitcoin#36: Verify integration tests using output of test file
040c57b Fix status for v18 types (Tobin C. Harding) 868d75d Fix status for v17 types (Tobin C. Harding) 16c697d verify: Verify tests using test output file (Tobin C. Harding) Pull request description: Currently the verify integration test code is broken because it greps for test names not bothering that some may be feature gated. Instead of grepping for integration tests by name instead accept an option that includes a file that is the output from running the integration tests and then grep that file. ACKs for top commit: apoelstra: ACK 040c57b; successfully ran local tests; neat! Tree-SHA512: 0ce79de13ac4412734a8e27b829daafe3610f5e290c02cf6a968f53f1ce01d8801d11c7c50eb0e603365c1b2abf4569947ebe3121345ccb57188cdecea1475a3
2 parents 4f10bd0 + 040c57b commit 7ff2e7f

File tree

3 files changed

+40
-53
lines changed

3 files changed

+40
-53
lines changed

types/src/v17/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
//!
6363
//! | JSON-PRC Method Name | Status |
6464
//! |:-----------------------------------|:---------------:|
65-
//! | generate | done |
65+
//! | generate | done (untested) |
6666
//! | generatetoaddress | done |
6767
//!
6868
//! </details>
@@ -143,7 +143,7 @@
143143
//! |:-----------------------------------|:---------------:|
144144
//! | abandontransaction | omitted |
145145
//! | abortrescan | omitted |
146-
//! | addmultisigaddress | done |
146+
//! | addmultisigaddress | done (untested) |
147147
//! | backupwallet | omitted |
148148
//! | bumpfee | done |
149149
//! | createwallet | done |
@@ -154,7 +154,7 @@
154154
//! | getaccountaddress | omitted |
155155
//! | getaddressbyaccount | omitted |
156156
//! | getaddressesbylabel | done |
157-
//! | getaddressinfo | done |
157+
//! | getaddressinfo | done (untested) |
158158
//! | getbalance | done |
159159
//! | getnewaddress | done |
160160
//! | getrawchangeaddress | done |

types/src/v18/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! | getblockcount | done |
2929
//! | getblockhash | done |
3030
//! | getblockheader | done |
31-
//! | getblockstats | done |
31+
//! | getblockstats | done (untested) |
3232
//! | getchaintips | done |
3333
//! | getchaintxstats | done |
3434
//! | getdifficulty | done |
@@ -68,7 +68,7 @@
6868
//!
6969
//! | JSON-PRC Method Name | Status |
7070
//! |:-----------------------------------|:---------------:|
71-
//! | generate | done |
71+
//! | generate | done (untested) |
7272
//! | generatetoaddress | done |
7373
//!
7474
//! </details>
@@ -126,7 +126,7 @@
126126
//! | fundrawtransaction | todo |
127127
//! | getrawtransaction | todo |
128128
//! | joinpsbts | todo |
129-
//! | sendrawtransaction | done |
129+
//! | sendrawtransaction | done (untested) |
130130
//! | signrawtransactionwithkey | todo |
131131
//! | testmempoolaccept | todo |
132132
//! | utxoupdatepsbt | todo |
@@ -155,15 +155,15 @@
155155
//! |:-----------------------------------|:---------------:|
156156
//! | abandontransaction | omitted |
157157
//! | abortrescan | omitted |
158-
//! | addmultisigaddress | done |
158+
//! | addmultisigaddress | done (untested) |
159159
//! | backupwallet | omitted |
160160
//! | bumpfee | done |
161161
//! | createwallet | done |
162162
//! | dumpprivkey | done |
163163
//! | dumpwallet | done |
164164
//! | encryptwallet | omitted |
165165
//! | getaddressesbylabel | done |
166-
//! | getaddressinfo | done |
166+
//! | getaddressinfo | done (untested) |
167167
//! | getbalance | done |
168168
//! | getnewaddress | done |
169169
//! | getrawchangeaddress | done |

verify/src/main.rs

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ fn main() -> Result<()> {
2626
let cmd = Command::new("verify")
2727
.args([
2828
arg!([version] "Verify specific version of Core (use \"all\" for all versions)").required(true),
29+
arg!(-t --tests <TEST_OUTPUT> "Optionally check claimed status of tests").required(false),
2930
]);
3031

3132
let matches = cmd.clone().get_matches();
3233
let version = matches.get_one::<String>("version").unwrap();
34+
let test_output = matches.get_one::<String>("tests");
3335

3436
if version == "all" {
35-
verify_all_versions()?;
37+
verify_all_versions(test_output)?;
3638
} else if let Ok(v) = version.parse::<Version>() {
37-
verify_version(v)?;
39+
verify_version(v, test_output)?;
3840
} else {
3941
eprint!("Unrecognised version: {} (supported versions:", version);
4042
for version in VERSIONS {
@@ -46,15 +48,15 @@ fn main() -> Result<()> {
4648
Ok(())
4749
}
4850

49-
fn verify_all_versions() -> Result<()> {
51+
fn verify_all_versions(test_output: Option<&String>) -> Result<()> {
5052
for version in VERSIONS {
5153
println!("Verifying for Bitcoin Core version {} ...\n", version);
52-
verify_version(version)?;
54+
verify_version(version, test_output)?;
5355
}
5456
Ok(())
5557
}
5658

57-
fn verify_version(version: Version) -> Result<()> {
59+
fn verify_version(version: Version, test_output: Option<&String>) -> Result<()> {
5860
let s = format!("{}::METHOD data", version);
5961
let msg = format!("Checking that the {} list is correct", s);
6062
check(&msg);
@@ -75,7 +77,7 @@ fn verify_version(version: Version) -> Result<()> {
7577

7678
let msg = "Checking that the status claimed in the version specific rustdocs is correct";
7779
check(msg);
78-
verify_status(version)?;
80+
verify_status(version, test_output)?;
7981
close(correct);
8082

8183
Ok(())
@@ -100,7 +102,7 @@ fn verify_correct_methods(version: Version, methods: Vec<String>, msg: &str) ->
100102
}
101103

102104
/// Verifies that the status we claim is correct.
103-
fn verify_status(version: Version) -> Result<()> {
105+
fn verify_status(version: Version, test_output: Option<&String>) -> Result<()> {
104106
let methods = versioned::methods_and_status(version)?;
105107
for method in methods {
106108
let out =
@@ -113,8 +115,10 @@ fn verify_status(version: Version) -> Result<()> {
113115
if !model::type_exists(version, &method.name)? {
114116
eprintln!("missing model type: {}", output_method(out));
115117
}
116-
if !check_integration_test_crate::test_exists(version, &method.name)? {
117-
eprintln!("missing integration test: {}", method.name);
118+
if let Some(test_output) = test_output {
119+
if !check_integration_test_crate::test_exists(version, &method.name, test_output)? {
120+
eprintln!("missing integration test: {}", method.name);
121+
}
118122
}
119123
}
120124
Status::Untested => {
@@ -125,8 +129,10 @@ fn verify_status(version: Version) -> Result<()> {
125129
eprintln!("missing model type: {}", output_method(out));
126130
}
127131
// Make sure we didn't forget to mark as tested after implementing integration test.
128-
if check_integration_test_crate::test_exists(version, &method.name)? {
129-
eprintln!("found integration test for untested method: {}", method.name);
132+
if let Some(test_output) = test_output {
133+
if check_integration_test_crate::test_exists(version, &method.name, test_output)? {
134+
eprintln!("found integration test for untested method: {}", method.name);
135+
}
130136
}
131137
}
132138
Status::Omitted | Status::Todo => { /* Nothing to verify */ }
@@ -158,49 +164,30 @@ mod check_integration_test_crate {
158164

159165
use crate::Version;
160166

161-
/// Path to the model module file.
162-
fn paths() -> Vec<PathBuf> {
163-
// TODO: "mining", "util", "zmq"
164-
let sections =
165-
["blockchain", "control", "generating", "network", "raw_transactions", "wallet"];
166-
let mut paths = vec![];
167-
for section in sections {
168-
paths.push(PathBuf::from(format!("../integration_test/tests/{}.rs", section)));
169-
}
170-
paths
171-
}
172-
173-
fn all_test_functions() -> Result<Vec<String>> {
167+
fn all_test_functions(test_output: &str) -> Result<Vec<String>> {
174168
let mut functions = vec![];
175169

176-
for path in paths() {
177-
let file = File::open(&path).with_context(|| {
178-
format!("Failed to grep for test functions in {}", path.display())
179-
})?;
180-
let reader = io::BufReader::new(file);
181-
182-
// let re = Regex::new(&regex::escape(r"fn ([a-z_]+)\(\) \{"))?;
183-
let fn_re = Regex::new(r"fn ([a-z_]+)")?;
184-
let todo_re = Regex::new(r"todo")?;
170+
let path = PathBuf::from(test_output);
171+
let file = File::open(&path).with_context(|| {
172+
format!("Failed to open test output file {}", path.display())
173+
})?;
174+
let reader = io::BufReader::new(file);
175+
let test_re = Regex::new(r"test ([a-z_]+) ... ok")?;
185176

186-
for line in reader.lines() {
187-
let line = line?;
177+
for line in reader.lines() {
178+
let line = line?;
188179

189-
if todo_re.is_match(&line) {
190-
continue;
191-
}
192-
193-
if let Some(caps) = fn_re.captures(&line) {
194-
let function = caps.get(1).unwrap().as_str();
195-
functions.push(function.to_string());
196-
}
180+
if let Some(caps) = test_re.captures(&line) {
181+
let function = caps.get(1).unwrap().as_str();
182+
functions.push(function.to_string());
197183
}
198184
}
185+
199186
Ok(functions)
200187
}
201188

202189
/// Checks that a type exists in `model` module.
203-
pub fn test_exists(version: Version, method_name: &str) -> Result<bool> {
190+
pub fn test_exists(version: Version, method_name: &str, test_output: &str) -> Result<bool> {
204191
let method = match method::Method::from_name(version, method_name) {
205192
Some(m) => m,
206193
None =>
@@ -210,7 +197,7 @@ mod check_integration_test_crate {
210197
))),
211198
};
212199

213-
let tests = all_test_functions()?;
200+
let tests = all_test_functions(test_output)?;
214201
if !tests.contains(&method.function.to_string()) {
215202
Ok(false)
216203
} else {

0 commit comments

Comments
 (0)