Skip to content

Commit 51575d7

Browse files
committed
Show experimental limit everywhere
1 parent c81b76c commit 51575d7

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

src/experimental_limit.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::process::Command;
2+
3+
#[cfg(not(windows))]
4+
fn get_echo_command() -> Command {
5+
Command::new("/bin/echo")
6+
}
7+
8+
#[cfg(windows)]
9+
fn get_echo_command() -> Command {
10+
let mut cmd = Command::new("cmd");
11+
cmd.arg("/c");
12+
cmd.arg("echo");
13+
cmd
14+
}
15+
16+
fn command_with_n_args_succeeds(n: i64) -> bool {
17+
use std::process::Stdio;
18+
get_echo_command()
19+
.args((0..n).map(|_| "foo"))
20+
.stdout(Stdio::null())
21+
.stderr(Stdio::null())
22+
.status()
23+
.map(|status| status.success())
24+
.unwrap_or(false)
25+
}
26+
27+
fn binary_search(mut lower: i64, mut upper: i64) -> i64 {
28+
while lower <= upper {
29+
let n = (lower + upper) / 2;
30+
31+
if command_with_n_args_succeeds(n) {
32+
lower = n + 1;
33+
} else {
34+
upper = n - 1;
35+
}
36+
}
37+
38+
lower
39+
}
40+
41+
pub(crate) fn experimental_arg_limit() -> i64 {
42+
std::env::set_var("WINEDEBUG", "-all");
43+
44+
binary_search(0, 1_000_000)
45+
}

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ use other as platform;
3333
#[cfg(unix)]
3434
use unix as platform;
3535

36+
#[cfg(test)]
37+
mod experimental_limit;
38+
3639
pub struct Command {
3740
inner: process::Command,
3841
remaining_argument_length: i64,

src/other.rs

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ pub(crate) fn available_argument_length<O: AsRef<OsStr>>(
2525
pub(crate) const fn max_single_argument_length() -> i64 {
2626
MAX_SINGLE_ARGUMENT_LENGTH
2727
}
28+
29+
#[test]
30+
fn show_experimental_limit() {
31+
use crate::experimental_limit::experimental_arg_limit;
32+
33+
println!("Experimental limit: {}", experimental_arg_limit());
34+
}

src/unix.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,7 @@ pub(crate) fn max_single_argument_length() -> i64 {
9595

9696
#[cfg(test)]
9797
mod tests {
98-
fn command_with_n_args_succeeds(n: i64) -> bool {
99-
use std::process::Stdio;
100-
std::process::Command::new("/bin/echo")
101-
.args((0..n).map(|_| "foo"))
102-
.stdout(Stdio::null())
103-
.stderr(Stdio::null())
104-
.status()
105-
.map(|status| status.success())
106-
.unwrap_or(false)
107-
}
108-
109-
fn binary_search(mut lower: i64, mut upper: i64) -> i64 {
110-
while lower <= upper {
111-
let n = (lower + upper) / 2;
112-
113-
if command_with_n_args_succeeds(n) {
114-
lower = n + 1;
115-
} else {
116-
upper = n - 1;
117-
}
118-
}
119-
120-
lower
121-
}
122-
123-
fn experimental_arg_limit() -> i64 {
124-
binary_search(0, 1_000_000)
125-
}
98+
use crate::experimental_limit::experimental_arg_limit;
12699

127100
#[test]
128101
fn available_argument_length_is_smaller_than_experimental_limit() {

0 commit comments

Comments
 (0)