Skip to content

Commit

Permalink
Use TestEnv::assert_ok everywhere
Browse files Browse the repository at this point in the history
`TestEnv::assert_ok` prints stderr and stdout, and so provides more
information in the event of an error.

type: reform
fixes:
- #330
  • Loading branch information
casey committed Apr 8, 2020
1 parent 8e3f551 commit 6edab1f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/subcommand/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod tests {
tree: {},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

assert!(env.out().starts_with("_imdl() {"));
}
Expand Down
26 changes: 13 additions & 13 deletions src/subcommand/torrent/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ mod tests {
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
}

#[test]
Expand Down Expand Up @@ -2231,7 +2231,7 @@ Content Size 9 bytes
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
}

#[test]
Expand All @@ -2248,7 +2248,7 @@ Content Size 9 bytes
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
assert_eq!(env.out(), "");
}

Expand All @@ -2267,7 +2267,7 @@ Content Size 9 bytes
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
assert_eq!(
env.out(),
"magnet:?xt=urn:btih:516735f4b80f2b5487eed5f226075bdcde33a54e&dn=foo\n"
Expand All @@ -2291,7 +2291,7 @@ Content Size 9 bytes
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
assert_eq!(
env.out(),
"magnet:\
Expand Down Expand Up @@ -2338,7 +2338,7 @@ Content Size 9 bytes
},
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();
assert_eq!(
env.out(),
"magnet:?xt=urn:btih:516735f4b80f2b5487eed5f226075bdcde33a54e&dn=foo&x.pe=foo:1337&x.pe=bar:\
Expand All @@ -2360,7 +2360,7 @@ Content Size 9 bytes
foo: "",
}
};
assert_matches!(env.run(), Ok(()));
env.assert_ok();
let torrent = env.resolve("foo.torrent")?;
let err = fs::read(torrent).unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::NotFound);
Expand Down Expand Up @@ -2388,7 +2388,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["a", "b", "c", "d/e"]);
Expand Down Expand Up @@ -2417,7 +2417,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["a", "b", "c", "d/e"]);
Expand Down Expand Up @@ -2446,7 +2446,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["d/a", "c", "b", "a"]);
Expand Down Expand Up @@ -2475,7 +2475,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["b", "d/e", "a", "c"]);
Expand Down Expand Up @@ -2504,7 +2504,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["c", "a", "b", "d/e"]);
Expand Down Expand Up @@ -2535,7 +2535,7 @@ Content Size 9 bytes
}
};

assert_matches!(env.run(), Ok(()));
env.assert_ok();

let torrent = env.load_metainfo("foo.torrent");
assert_eq!(torrent.file_paths(), &["d/e", "b", "a", "c"]);
Expand Down
11 changes: 5 additions & 6 deletions src/subcommand/torrent/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl Link {
mod tests {
use super::*;

use claim::assert_ok;
use pretty_assertions::assert_eq;

#[test]
Expand All @@ -85,7 +84,7 @@ mod tests {
}
};

assert_ok!(env.run());
env.assert_ok();

const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";

Expand Down Expand Up @@ -114,7 +113,7 @@ mod tests {
}
};

assert_ok!(env.run());
env.assert_ok();

const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";

Expand Down Expand Up @@ -147,7 +146,7 @@ mod tests {
}
};

assert_ok!(env.run());
env.assert_ok();

const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";

Expand Down Expand Up @@ -180,7 +179,7 @@ mod tests {
}
};

assert_ok!(env.run());
env.assert_ok();

const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";

Expand Down Expand Up @@ -209,7 +208,7 @@ mod tests {
}
};

assert_ok!(env.run());
env.assert_ok();

const INFO: &str = "d1:ai0e6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";

Expand Down
16 changes: 8 additions & 8 deletions src/subcommand/torrent/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod tests {

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = " Name foo
Expand Down Expand Up @@ -108,7 +108,7 @@ Announce List Tier 1: announce

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = "\
Expand Down Expand Up @@ -173,7 +173,7 @@ files\tfoo

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = " Name foo
Expand Down Expand Up @@ -210,7 +210,7 @@ Announce List Tier 1: x

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = "\
Expand Down Expand Up @@ -275,7 +275,7 @@ files\tfoo

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = " Name foo
Expand Down Expand Up @@ -312,7 +312,7 @@ Announce List Tier 1: b

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = "\
Expand Down Expand Up @@ -377,7 +377,7 @@ files\tfoo

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = " Name foo
Expand Down Expand Up @@ -410,7 +410,7 @@ Creation Date 1970-01-01 00:00:01 UTC

metainfo.dump(path).unwrap();

env.run().unwrap();
env.assert_ok();

let have = env.out();
let want = "\
Expand Down
24 changes: 12 additions & 12 deletions src/subcommand/torrent/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand All @@ -133,7 +133,7 @@ mod tests {
tree: {},
};

assert_matches!(verify_env.run(), Ok(()));
verify_env.assert_ok();

let want = format!(
"[1/2] \u{1F4BE} Loading metainfo from `{}`…\n[2/2] \u{1F9EE} Verifying pieces from \
Expand Down Expand Up @@ -168,7 +168,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

create_env.write("foo/a", "xyz");

Expand Down Expand Up @@ -227,7 +227,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand All @@ -249,7 +249,7 @@ mod tests {
tree: {},
};

assert_matches!(verify_env.run(), Ok(()));
verify_env.assert_ok();

let want = format!(
"[1/2] \u{1F4BE} Loading metainfo from `{}`…\n[2/2] \u{1F9EE} Verifying pieces from \
Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;
let content = create_env.resolve("foo")?;
Expand All @@ -302,7 +302,7 @@ mod tests {
tree: {},
};

assert_matches!(verify_env.run(), Ok(()));
verify_env.assert_ok();

let want = format!(
"[1/2] \u{1F4BE} Loading metainfo from standard input…\n[2/2] \u{1F9EE} Verifying pieces \
Expand Down Expand Up @@ -340,7 +340,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand Down Expand Up @@ -425,7 +425,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand Down Expand Up @@ -531,7 +531,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand Down Expand Up @@ -591,7 +591,7 @@ mod tests {
},
};

create_env.run()?;
create_env.assert_ok();

let torrent = create_env.resolve("foo.torrent")?;

Expand All @@ -610,7 +610,7 @@ mod tests {

fs::rename(create_env.resolve("foo")?, verify_env.resolve("foo")?).unwrap();

assert_matches!(verify_env.run(), Ok(()));
verify_env.assert_ok();

let want = format!(
"[1/2] \u{1F4BE} Loading metainfo from standard input…\n[2/2] \u{1F9EE} Verifying pieces \
Expand Down
4 changes: 2 additions & 2 deletions src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mod tests {
},
};

env.run()?;
env.assert_ok();

let metainfo = env.load_metainfo("foo.torrent");

Expand Down Expand Up @@ -171,7 +171,7 @@ mod tests {
},
};

env.run()?;
env.assert_ok();

env.write("foo/a", "xyz");

Expand Down

0 comments on commit 6edab1f

Please sign in to comment.