Skip to content

Commit 57763c7

Browse files
committed
test: demonstrate the current precedence of finding --jobserver-auth
1 parent 97da63e commit 57763c7

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/lib.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,9 @@ impl HelperState {
585585
}
586586

587587
fn find_jobserver_auth(var: &str) -> Option<(&str, usize)> {
588-
["--jobserver-fds=", "--jobserver-auth="]
588+
["--jobserver-auth=", "--jobserver-fds="]
589589
.iter()
590-
.map(|&arg| var.find(arg).map(|pos| (arg, pos)))
590+
.map(|&arg| var.rfind(arg).map(|pos| (arg, pos)))
591591
.find_map(|pos| pos)
592592
}
593593

@@ -597,3 +597,32 @@ fn no_helper_deadlock() {
597597
let _y = x.clone();
598598
std::mem::drop(x.into_helper_thread(|_| {}).unwrap());
599599
}
600+
601+
#[test]
602+
fn test_find_jobserver_auth() {
603+
let cases = [
604+
(
605+
"--jobserver-auth= --jobserver-auth=",
606+
("--jobserver-auth=", 18),
607+
),
608+
(
609+
"--jobserver-fds= --jobserver-fds=",
610+
("--jobserver-fds=", 17),
611+
),
612+
(
613+
"--jobserver-auth= --jobserver-fds= --jobserver-auth=",
614+
("--jobserver-auth=", 35),
615+
),
616+
(
617+
"--jobserver-fds= --jobserver-auth= --jobserver-fds=",
618+
("--jobserver-auth=", 17),
619+
),
620+
];
621+
for (var, expected) in cases {
622+
let actual = find_jobserver_auth(var).unwrap();
623+
assert_eq!(
624+
actual, expected,
625+
"expect {expected:?}, got {actual:?}, input `{var:?}`"
626+
);
627+
}
628+
}

0 commit comments

Comments
 (0)