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

std: Move a process test out of libstd #62183

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1765,33 +1765,6 @@ mod tests {
assert_eq!(out, "foobar\n");
}


#[test]
#[cfg_attr(target_os = "android", ignore)]
#[cfg(unix)]
fn uid_works() {
use crate::os::unix::prelude::*;

let mut p = Command::new("/bin/sh")
.arg("-c").arg("true")
.uid(unsafe { libc::getuid() })
.gid(unsafe { libc::getgid() })
.spawn().unwrap();
assert!(p.wait().unwrap().success());
}

#[test]
#[cfg_attr(target_os = "android", ignore)]
#[cfg(unix)]
fn uid_to_root_fails() {
use crate::os::unix::prelude::*;

// if we're already root, this isn't a valid test. Most of the bots run
// as non-root though (android is an exception).
if unsafe { libc::getuid() == 0 } { return }
assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err());
}

#[test]
#[cfg_attr(target_os = "android", ignore)]
fn test_process_status() {
Expand Down
26 changes: 26 additions & 0 deletions src/test/run-pass/command-uid-gid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![feature(rustc_private)]

fn main() {
#[cfg(unix)]
run()
}

#[cfg(unix)]
fn run() {
extern crate libc;
use std::process::Command;
use std::os::unix::prelude::*;

let mut p = Command::new("/bin/sh")
.arg("-c").arg("true")
.uid(unsafe { libc::getuid() })
.gid(unsafe { libc::getgid() })
.spawn().unwrap();
assert!(p.wait().unwrap().success());

// if we're already root, this isn't a valid test. Most of the bots run
// as non-root though (android is an exception).
if unsafe { libc::getuid() != 0 } {
assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err());
}
}