diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-05-05 14:33:55 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-05-14 22:52:31 -0700 |
| commit | 046062d3bf0597fb2f40f7cacbbe4f438506247d (patch) | |
| tree | e0333e7bb2ef925fd0e3c18b9545e54f90a67f3e /src/test/run-make/unicode-input | |
| parent | 8f9cbe08c61b05527e6d48589d4a963126448467 (diff) | |
| download | rust-046062d3bf0597fb2f40f7cacbbe4f438506247d.tar.gz rust-046062d3bf0597fb2f40f7cacbbe4f438506247d.zip | |
Process::new etc should support non-utf8 commands/args
The existing APIs for spawning processes took strings for the command and arguments, but the underlying system may not impose utf8 encoding, so this is overly limiting. The assumption we actually want to make is just that the command and arguments are viewable as [u8] slices with no interior NULLs, i.e., as CStrings. The ToCStr trait is a handy bound for types that meet this requirement (such as &str and Path). However, since the commands and arguments are often a mixture of strings and paths, it would be inconvenient to take a slice with a single T: ToCStr bound. So this patch revamps the process creation API to instead use a builder-style interface, called `Command`, allowing arguments to be added one at a time with differing ToCStr implementations for each. The initial cut of the builder API has some drawbacks that can be addressed once issue #13851 (libstd as a facade) is closed. These are detailed as FIXMEs. Closes #11650. [breaking-change]
Diffstat (limited to 'src/test/run-make/unicode-input')
| -rw-r--r-- | src/test/run-make/unicode-input/multiple_files.rs | 7 | ||||
| -rw-r--r-- | src/test/run-make/unicode-input/span_length.rs | 8 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/test/run-make/unicode-input/multiple_files.rs b/src/test/run-make/unicode-input/multiple_files.rs index a08d6bb0bf8..219eb1a3ebd 100644 --- a/src/test/run-make/unicode-input/multiple_files.rs +++ b/src/test/run-make/unicode-input/multiple_files.rs @@ -12,7 +12,7 @@ extern crate rand; use rand::{task_rng, Rng}; use std::{char, os, str}; -use std::io::{File, Process}; +use std::io::{File, Command}; // creates unicode_input_multiple_files_{main,chars}.rs, where the // former imports the latter. `_chars` just contains an indentifier @@ -40,7 +40,6 @@ fn main() { let tmpdir = Path::new(args.get(2).as_slice()); let main_file = tmpdir.join("unicode_input_multiple_files_main.rs"); - let main_file_str = main_file.as_str().unwrap(); { let _ = File::create(&main_file).unwrap() .write_str("mod unicode_input_multiple_files_chars;"); @@ -57,7 +56,9 @@ fn main() { // rustc is passed to us with --out-dir and -L etc., so we // can't exec it directly - let result = Process::output("sh", ["-c".to_owned(), rustc + " " + main_file_str]).unwrap(); + let result = Command::new("sh") + .arg("-c").arg(rustc + " " + main_file.as_str().unwrap()) + .output().unwrap(); let err = str::from_utf8_lossy(result.error.as_slice()); // positive test so that this test will be updated when the diff --git a/src/test/run-make/unicode-input/span_length.rs b/src/test/run-make/unicode-input/span_length.rs index d5614975215..2bb89d76213 100644 --- a/src/test/run-make/unicode-input/span_length.rs +++ b/src/test/run-make/unicode-input/span_length.rs @@ -12,7 +12,7 @@ extern crate rand; use rand::{task_rng, Rng}; use std::{char, os, str}; -use std::io::{File, Process}; +use std::io::{File, Command}; // creates a file with `fn main() { <random ident> }` and checks the // compiler emits a span of the appropriate length (for the @@ -37,9 +37,7 @@ fn main() { let args = os::args(); let rustc = args.get(1).as_slice(); let tmpdir = Path::new(args.get(2).as_slice()); - let main_file = tmpdir.join("span_main.rs"); - let main_file_str = main_file.as_str().unwrap(); for _ in range(0, 100) { let n = task_rng().gen_range(3u, 20); @@ -53,7 +51,9 @@ fn main() { // rustc is passed to us with --out-dir and -L etc., so we // can't exec it directly - let result = Process::output("sh", ["-c".to_owned(), rustc + " " + main_file_str]).unwrap(); + let result = Command::new("sh") + .arg("-c").arg(rustc + " " + main_file.as_str().unwrap()) + .output().unwrap(); let err = str::from_utf8_lossy(result.error.as_slice()); |
