Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process::ExitStatus should have some kind of constructor #32713

Closed
nrc opened this issue Apr 3, 2016 · 8 comments
Closed

process::ExitStatus should have some kind of constructor #32713

nrc opened this issue Apr 3, 2016 · 8 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@nrc
Copy link
Member

nrc commented Apr 3, 2016

Because ExitStatus has a private field it is impossible to create one in user code, one must actually execute a process. This prevents testing/mocking. My use case is that I have some function which runs a process and generates data, however, for testing I want to mock the test run and just return a success exit status and some data. I can't do that because I can't create my own ExitStatus objects.

At the least there should be a way to create a success ExitStatus. Preferably, there would be a way to create various fail statuses too.

@nrc nrc added A-libs labels Apr 3, 2016
@frewsxcv
Copy link
Member

frewsxcv commented Apr 4, 2016

Should the constructor just take an i32?

@alexcrichton
Copy link
Member

I've also wanted a basically "raw constructor" in the past. I'd be fine adding some std::os extensions which allow construction from a c_int or DWORD (i32 and u32)

@jirutka
Copy link

jirutka commented Apr 26, 2016

+1
I’d like to extend Command, but I cannot reuse Output for return value because I can’t construct ExitStatus. :(

@alexcrichton
Copy link
Member

I've opened a PR for this over at #33224

@jirutka
Copy link

jirutka commented Apr 26, 2016

Great, thanks! 👍

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 27, 2016
Sometimes a process may be waited on externally from the standard library, in
which case it can be useful to create a raw `ExitStatus` structure to return.
This commit extends the existing Unix `ExitStatusExt` extension trait and adds a
new Windows-specific `ExitStatusExt` extension trait to do this. The methods are
currently called `ExitStatus::from_raw`.

cc rust-lang#32713
Manishearth added a commit to Manishearth/rust that referenced this issue May 9, 2016
…aturon

std: Allow creating ExitStatus from raw values

Sometimes a process may be waited on externally from the standard library, in
which case it can be useful to create a raw `ExitStatus` structure to return.
This commit extends the existing Unix `ExitStatusExt` extension trait and adds a
new Windows-specific `ExitStatusExt` extension trait to do this. The methods are
currently called `ExitStatus::from_raw`.

cc rust-lang#32713
Manishearth added a commit to Manishearth/rust that referenced this issue May 9, 2016
…aturon

std: Allow creating ExitStatus from raw values

Sometimes a process may be waited on externally from the standard library, in
which case it can be useful to create a raw `ExitStatus` structure to return.
This commit extends the existing Unix `ExitStatusExt` extension trait and adds a
new Windows-specific `ExitStatusExt` extension trait to do this. The methods are
currently called `ExitStatus::from_raw`.

cc rust-lang#32713
bors added a commit that referenced this issue May 9, 2016
std: Allow creating ExitStatus from raw values

Sometimes a process may be waited on externally from the standard library, in
which case it can be useful to create a raw `ExitStatus` structure to return.
This commit extends the existing Unix `ExitStatusExt` extension trait and adds a
new Windows-specific `ExitStatusExt` extension trait to do this. The methods are
currently called `ExitStatus::from_raw`.

cc #32713
Manishearth added a commit to Manishearth/rust that referenced this issue May 9, 2016
…aturon

std: Allow creating ExitStatus from raw values

Sometimes a process may be waited on externally from the standard library, in
which case it can be useful to create a raw `ExitStatus` structure to return.
This commit extends the existing Unix `ExitStatusExt` extension trait and adds a
new Windows-specific `ExitStatusExt` extension trait to do this. The methods are
currently called `ExitStatus::from_raw`.

cc rust-lang#32713
@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. labels Jun 21, 2016
@joelself
Copy link

joelself commented Jul 6, 2016

This would help n00bs like me who start out by copying the example code and tweaking it:

let output = Command::new("sh")
                     .arg("-c")
                     .arg("echo hello")
                     .output()
                     .unwrap_or_else(|e| { panic!("failed to execute process: {}", e) });

This example is a special case that only happens to work if the unwrap_or_else contains a panic! or something else that immediately exits. Otherwise you need to create your own Output struct to return which is currently impossible.

@alexcrichton alexcrichton added I-nominated final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed I-nominated labels Jul 11, 2016
@alexcrichton
Copy link
Member

🔔 This issue is now entering a cycle-long final comment period for stabilization 🔔

@alexcrichton
Copy link
Member

Discussed recently, the libs team decided to stabilize.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 18, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
bors added a commit that referenced this issue Aug 18, 2016
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 19, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
bors added a commit that referenced this issue Aug 20, 2016
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 23, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants