Skip to content

Commit ae468aa

Browse files
ref(clippy): Enable tests-outside-test-module lint
Enable the [`tests-outside-test-module`](https://rust-lang.github.io/rust-clippy/master/index.html#tests_outside_test_module) Clippy lint, and fix violations. This lint will enforce the convention that `#[test]` items must be placed within a `#[cfg(test)]` module.
1 parent ce8d59d commit ae468aa

File tree

6 files changed

+691
-673
lines changed

6 files changed

+691
-673
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ with_crash_reporting = []
9898
allow-attributes = "warn"
9999
str-to-string = "warn"
100100
string-to-string = "warn"
101+
tests-outside-test-module = "warn"
101102
unnecessary-wraps = "warn"
102103
uninlined-format-args = "warn"
103104
unused-trait-names = "warn"

src/commands/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ pub fn main() -> ! {
392392
process::exit(exit_code);
393393
}
394394

395-
#[test]
396-
fn verify_app() {
397-
app().debug_assert();
395+
#[cfg(test)]
396+
mod tests {
397+
use super::*;
398+
399+
#[test]
400+
fn verify_app() {
401+
app().debug_assert();
402+
}
398403
}

src/commands/sourcemaps/explain.rs

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -467,52 +467,57 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
467467
Ok(())
468468
}
469469

470-
#[test]
471-
fn test_resolve_sourcemap_url() {
472-
// Tests coming from `tests/sentry/utils/test_urls.py` in `getsentry/sentry`
473-
let cases = vec![
474-
("http://example.com/foo", "bar", "http://example.com/bar"),
475-
("http://example.com/foo", "/bar", "http://example.com/bar"),
476-
("https://example.com/foo", "/bar", "https://example.com/bar"),
477-
(
478-
"http://example.com/foo/baz",
479-
"bar",
480-
"http://example.com/foo/bar",
481-
),
482-
(
483-
"http://example.com/foo/baz",
484-
"/bar",
485-
"http://example.com/bar",
486-
),
487-
("aps://example.com/foo", "/bar", "aps://example.com/bar"),
488-
(
489-
"apsunknown://example.com/foo",
490-
"/bar",
491-
"apsunknown://example.com/bar",
492-
),
493-
(
494-
"apsunknown://example.com/foo",
495-
"//aha/uhu",
496-
"apsunknown://aha/uhu",
497-
),
498-
];
499-
500-
for (base, to_join, expected) in cases {
501-
assert_eq!(resolve_sourcemap_url(base, to_join).unwrap(), expected);
470+
#[cfg(test)]
471+
mod tests {
472+
use super::*;
473+
474+
#[test]
475+
fn test_resolve_sourcemap_url() {
476+
// Tests coming from `tests/sentry/utils/test_urls.py` in `getsentry/sentry`
477+
let cases = vec![
478+
("http://example.com/foo", "bar", "http://example.com/bar"),
479+
("http://example.com/foo", "/bar", "http://example.com/bar"),
480+
("https://example.com/foo", "/bar", "https://example.com/bar"),
481+
(
482+
"http://example.com/foo/baz",
483+
"bar",
484+
"http://example.com/foo/bar",
485+
),
486+
(
487+
"http://example.com/foo/baz",
488+
"/bar",
489+
"http://example.com/bar",
490+
),
491+
("aps://example.com/foo", "/bar", "aps://example.com/bar"),
492+
(
493+
"apsunknown://example.com/foo",
494+
"/bar",
495+
"apsunknown://example.com/bar",
496+
),
497+
(
498+
"apsunknown://example.com/foo",
499+
"//aha/uhu",
500+
"apsunknown://aha/uhu",
501+
),
502+
];
503+
504+
for (base, to_join, expected) in cases {
505+
assert_eq!(resolve_sourcemap_url(base, to_join).unwrap(), expected);
506+
}
502507
}
503-
}
504508

505-
#[test]
506-
fn test_unify_artifact_url() {
507-
let cases = vec![
508-
(
509-
"http://localhost:5000/dist/bundle.min.js",
510-
"~/dist/bundle.min.js",
511-
),
512-
("/dist/bundle.js.map", "~/dist/bundle.js.map"),
513-
];
514-
515-
for (path, expected) in cases {
516-
assert_eq!(unify_artifact_url(path).unwrap(), expected);
509+
#[test]
510+
fn test_unify_artifact_url() {
511+
let cases = vec![
512+
(
513+
"http://localhost:5000/dist/bundle.min.js",
514+
"~/dist/bundle.min.js",
515+
),
516+
("/dist/bundle.js.map", "~/dist/bundle.js.map"),
517+
];
518+
519+
for (path, expected) in cases {
520+
assert_eq!(unify_artifact_url(path).unwrap(), expected);
521+
}
517522
}
518523
}

src/utils/http.rs

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,45 @@ pub fn is_absolute_url(url: &str) -> bool {
7272
url.starts_with("http://") || url.starts_with("https://")
7373
}
7474

75-
#[test]
76-
fn test_parse_link_header() {
77-
let rv = parse_link_header("<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\", <https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0>; rel=\"next\"; results=\"true\"; cursor=\"100:1:0\"");
78-
assert_eq!(rv.len(), 2);
79-
80-
let a = &rv[0];
81-
let b = &rv[1];
82-
83-
assert_eq!(
84-
a.get("_link").unwrap(),
85-
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1"
86-
);
87-
assert_eq!(a.get("cursor").unwrap(), &"100:-1:1");
88-
assert_eq!(a.get("rel").unwrap(), &"previous");
89-
assert_eq!(a.get("results").unwrap(), &"false");
90-
91-
assert_eq!(
92-
b.get("_link").unwrap(),
93-
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0"
94-
);
95-
assert_eq!(b.get("cursor").unwrap(), &"100:1:0");
96-
assert_eq!(b.get("rel").unwrap(), &"next");
97-
assert_eq!(b.get("results").unwrap(), &"true");
98-
}
75+
#[cfg(test)]
76+
mod tests {
77+
use super::*;
78+
79+
#[test]
80+
fn test_parse_link_header() {
81+
let rv = parse_link_header("<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\", <https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0>; rel=\"next\"; results=\"true\"; cursor=\"100:1:0\"");
82+
assert_eq!(rv.len(), 2);
83+
84+
let a = &rv[0];
85+
let b = &rv[1];
86+
87+
assert_eq!(
88+
a.get("_link").unwrap(),
89+
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1"
90+
);
91+
assert_eq!(a.get("cursor").unwrap(), &"100:-1:1");
92+
assert_eq!(a.get("rel").unwrap(), &"previous");
93+
assert_eq!(a.get("results").unwrap(), &"false");
9994

100-
#[test]
101-
fn test_is_absolute_url() {
102-
assert!(is_absolute_url("https://sentry.io"));
103-
assert!(is_absolute_url("http://sentry.io"));
104-
assert!(is_absolute_url("https://sentry.io/path"));
105-
assert!(is_absolute_url("http://sentry.io/path"));
106-
assert!(is_absolute_url("http://sentry.io/path?query=foo"));
107-
assert!(is_absolute_url("https://sentry.io/path?query=foo"));
108-
109-
assert!(!is_absolute_url("/path"));
110-
assert!(!is_absolute_url("/path?query=foo"));
95+
assert_eq!(
96+
b.get("_link").unwrap(),
97+
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0"
98+
);
99+
assert_eq!(b.get("cursor").unwrap(), &"100:1:0");
100+
assert_eq!(b.get("rel").unwrap(), &"next");
101+
assert_eq!(b.get("results").unwrap(), &"true");
102+
}
103+
104+
#[test]
105+
fn test_is_absolute_url() {
106+
assert!(is_absolute_url("https://sentry.io"));
107+
assert!(is_absolute_url("http://sentry.io"));
108+
assert!(is_absolute_url("https://sentry.io/path"));
109+
assert!(is_absolute_url("http://sentry.io/path"));
110+
assert!(is_absolute_url("http://sentry.io/path?query=foo"));
111+
assert!(is_absolute_url("https://sentry.io/path?query=foo"));
112+
113+
assert!(!is_absolute_url("/path"));
114+
assert!(!is_absolute_url("/path?query=foo"));
115+
}
111116
}

0 commit comments

Comments
 (0)