Merge pull request #882 from jbcrail/fix-windows-build

Improve Windows build
This commit is contained in:
Heather 2016-05-22 16:02:03 +04:00
commit bdc1ca7426
57 changed files with 128 additions and 211 deletions

26
Cargo.lock generated
View file

@ -12,6 +12,7 @@ dependencies = [
"comm 0.0.1",
"cp 0.0.1",
"cut 0.0.1",
"dircolors 0.0.1",
"dirname 0.0.1",
"du 0.0.1",
"echo 0.0.1",
@ -39,6 +40,7 @@ dependencies = [
"memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"mkdir 0.0.1",
"mkfifo 0.0.1",
"mknod 0.0.1",
"mktemp 0.0.1",
"mv 0.0.1",
"nice 0.0.1",
@ -208,6 +210,16 @@ dependencies = [
"uucore 0.0.1",
]
[[package]]
name = "dircolors"
version = "0.0.1"
dependencies = [
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"uucore 0.0.1",
]
[[package]]
name = "dirname"
version = "0.0.1"
@ -324,6 +336,11 @@ name = "getopts"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "groups"
version = "0.0.1"
@ -482,6 +499,15 @@ dependencies = [
"uucore 0.0.1",
]
[[package]]
name = "mknod"
version = "0.0.1"
dependencies = [
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"uucore 0.0.1",
]
[[package]]
name = "mktemp"
version = "0.0.1"

View file

@ -194,3 +194,6 @@ tempdir="*"
[[bin]]
name = "uutils"
path = "src/uutils/uutils.rs"
[[test]]
name = "tests"

View file

@ -12,12 +12,9 @@ install:
- cargo -V
build_script:
- cargo build --features generic --no-default-features
- 7z a -tzip uutils.zip .\target\release\deps\*.exe
- cargo build --release --features generic --no-default-features
artifacts:
- path: uutils.zip
name: zipfile
- path: target\release\uutils.exe
name: uutils.exe

View file

@ -13,7 +13,6 @@ extern crate uucore;
use std::io::{Error, Result};
use std::mem;
use std::os::windows::ffi::OsStringExt;
use uucore::wide::FromWide;
pub unsafe fn getusername() -> Result<String> {

View file

@ -1,7 +1,5 @@
#![allow(dead_code)]
extern crate tempdir;
use std::env;
use std::fs::{self, File, OpenOptions};
use std::io::{Read, Write, Result};
@ -14,10 +12,10 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio, Child};
use std::str::from_utf8;
use std::ffi::OsStr;
use self::tempdir::TempDir;
use std::rc::Rc;
use std::thread::sleep;
use std::time::Duration;
use tempdir::TempDir;
#[cfg(windows)]
static PROGNAME: &'static str = "target\\debug\\uutils.exe";
@ -71,15 +69,17 @@ pub fn repeat_str(s: &str, n: u32) -> String {
#[macro_export]
macro_rules! path_concat {
($e:expr, ..$n:expr) => {{
use std::path::PathBuf;
let n = $n;
let mut pb = std::path::PathBuf::new();
let mut pb = PathBuf::new();
for _ in 0..n {
pb.push($e);
}
pb.to_str().unwrap().to_owned()
}};
($($e:expr),*) => {{
let mut pb = std::path::PathBuf::new();
use std::path::PathBuf;
let mut pb = PathBuf::new();
$(
pb.push($e);
)*

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "base64";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "basename";
@ -44,6 +41,7 @@ fn expect_error(input: Vec<&str>, expected_stdout: &str) {
assert!(results.stderr.len() > 0);
assert_eq!(expected_stdout, results.stdout.trim_right());
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_multiple_param() {

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "cat";

View file

@ -1,33 +1,29 @@
#[macro_use]
mod common;
use std::os::unix::raw::mode_t;
use std::os::unix::fs::PermissionsExt;
use std::os::unix::fs::OpenOptionsExt;
use common::util::*;
use std::fs::{metadata, OpenOptions, set_permissions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
static UTIL_NAME: &'static str = "chmod";
static TEST_FILE: &'static str = "file";
static REFERENCE_FILE: &'static str = "reference";
static REFERENCE_PERMS: mode_t = 0o247;
static REFERENCE_PERMS: u32 = 0o247;
struct TestCase {
args: Vec<&'static str>,
before: mode_t,
after: mode_t
before: u32,
after: u32
}
fn mkfile(file: &str, mode: mode_t) {
std::fs::OpenOptions::new().mode(mode).create(true).write(true).open(file).unwrap();
let mut perms = std::fs::metadata(file).unwrap().permissions();
fn mkfile(file: &str, mode: u32) {
OpenOptions::new().mode(mode).create(true).write(true).open(file).unwrap();
let mut perms = metadata(file).unwrap().permissions();
perms.set_mode(mode);
std::fs::set_permissions(file, perms).unwrap();
set_permissions(file, perms).unwrap();
}
fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
mkfile(&at.plus_as_string(TEST_FILE), test.before);
let perms = at.metadata(TEST_FILE).permissions().mode();
if perms != test.before{
if perms != test.before {
panic!(format!("{}: expected: {:o} got: {:o}", "setting permissions failed", test.after, perms));
}

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "cksum";

View file

@ -1,8 +1,6 @@
#[macro_use]
mod common;
use common::util::testing;
use std::ffi::OsStr;
static UTIL_NAME: &'static str = "comm";
fn comm<A: AsRef<OsStr>, B: AsRef<str>>(args: &[A],

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "cp";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "cut";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "dircolors";

View file

@ -1,11 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "dirname";
#[test]
fn test_path_with_trailing_slashes() {
let (_, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "echo";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "env";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "expr";

View file

@ -7,21 +7,11 @@
// that was distributed with this source code.
//
#[macro_use]
mod common;
use common::util::*;
extern crate libc;
extern crate rand;
use rand::{weak_rng, Rng};
use rand::distributions::{IndependentSample, Range};
use sieve::Sieve;
#[path="../src/factor/sieve.rs"]
mod sieve;
const NUM_PRIMES: usize = 10000;
const LOG_PRIMES: f64 = 14.0; // ceil(log2(NUM_PRIMES))

View file

@ -1,11 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "false";
#[test]
fn test_exit_code() {
let (_, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "fold";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
macro_rules! get_hash(
($str:expr) => (
$str.split(' ').collect::<Vec<&str>>()[0]

View file

@ -1,13 +1,9 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "head";
static INPUT: &'static str = "lorem_ipsum.txt";
#[test]
fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
extern crate libc;
use common::util::*;

View file

@ -1,12 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "ln";
#[test]
fn test_symlink_existing_file() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,16 +1,13 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "ls";
#[test]
fn test_ls_ls() {
let (at, mut ucmd) = testing(UTIL_NAME);
let (_, mut ucmd) = testing(UTIL_NAME);
let result = ucmd.run();
let exit_success = result.success;
assert_eq!(exit_success, true);
}
}

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "mkdir";
@ -11,7 +8,6 @@ static TEST_DIR3: &'static str = "mkdir_test3";
static TEST_DIR4: &'static str = "mkdir_test4/mkdir_test4_1";
static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1";
#[test]
fn test_mkdir_mkdir() {
let (_, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,8 +1,5 @@
#[macro_use]
mod common;
use common::util::*;
use common::util::tempdir::TempDir;
use tempdir::TempDir;
static UTIL_NAME: &'static str = "mktemp";
@ -20,7 +17,6 @@ static TEST_TEMPLATE8: &'static str = "tempXXXla\\te";
const TMPDIR: &'static str = "TMPDIR";
#[test]
fn test_mktemp_mktemp() {
let ts = TestSet::new(UTIL_NAME);

View file

@ -1,13 +1,10 @@
#[macro_use]
mod common;
extern crate libc;
extern crate time;
extern crate kernel32;
extern crate winapi;
extern crate filetime;
use filetime::*;
use self::filetime::*;
use common::util::*;
static UTIL_NAME: &'static str = "mv";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "nl";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
use std::path::Path;
use std::env;

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "paste";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "printf";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "ptx";

View file

@ -1,11 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "pwd";
#[test]
fn test_default() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,13 +1,9 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "readlink";
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
#[test]
fn test_canonicalize() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "realpath";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "rm";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
extern crate libc;
use common::util::*;

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "seq";

View file

@ -1,11 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "sort";
#[test]
fn test_numeric_floats_and_ints() {
test_helper("numeric_floats_and_ints", "-n");

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
extern crate rand;
extern crate regex;
@ -13,8 +10,6 @@ use common::util::*;
static UTIL_NAME: &'static str = "split";
fn random_chars(n: usize) -> String {
thread_rng().gen_ascii_chars().take(n).collect::<String>()
}

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "stdbuf";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "sum";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "tac";

View file

@ -1,13 +1,9 @@
extern crate uu_tail;
use uu_tail::parse_size;
use std::io::Read;
use std::io::Write;
#[macro_use]
mod common;
use common::util::*;
use std::char::from_digit;
use std::io::{Read, Write};
use uu_tail::parse_size;
static UTIL_NAME: &'static str = "tail";
@ -110,14 +106,14 @@ fn test_bytes_big() {
let mut big_input = at.make_scoped_file(FILE);
for i in 0..BYTES {
let digit = std::char::from_digit((i % 10) as u32, 10).unwrap();
let digit = from_digit((i % 10) as u32, 10).unwrap();
write!(&mut big_input, "{}", digit).expect("Could not write to FILE");
}
big_input.flush().expect("Could not flush FILE");
let mut big_expected = at.make_scoped_file(EXPECTED_FILE);
for i in (BYTES - N_ARG)..BYTES {
let digit = std::char::from_digit((i % 10) as u32, 10).unwrap();
let digit = from_digit((i % 10) as u32, 10).unwrap();
write!(&mut big_expected, "{}", digit).expect("Could not write to EXPECTED_FILE");
}
big_expected.flush().expect("Could not flush EXPECTED_FILE");

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
//
// This file is part of the uutils coreutils package.
//
@ -14,7 +11,6 @@ use common::util::*;
static UTIL_NAME: &'static str = "test";
#[test]
fn test_op_prec_and_or_1() {
let (_, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,11 +1,8 @@
#[macro_use]
mod common;
extern crate time;
extern crate filetime;
extern crate time;
use filetime::FileTime;
use common::util::*;
use self::filetime::FileTime;
static UTIL_NAME: &'static str = "touch";

View file

@ -1,12 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "tr";
#[test]
fn test_toupper() {
let (_, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "true";

View file

@ -1,8 +1,5 @@
#[macro_use]
mod common;
use std::io::{Seek, SeekFrom, Write};
use common::util::*;
use std::io::{Seek, SeekFrom, Write};
static UTIL_NAME: &'static str = "truncate";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "tsort";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "unexpand";

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "uniq";
@ -9,7 +6,6 @@ static INPUT: &'static str = "sorted.txt";
static SKIP_CHARS: &'static str = "skip-chars.txt";
static SKIP_FIELDS: &'static str = "skip-fields.txt";
#[test]
fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,11 +1,7 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "unlink";
#[test]
fn test_unlink_file() {
let (at, mut ucmd) = testing(UTIL_NAME);

View file

@ -1,6 +1,3 @@
#[macro_use]
mod common;
use common::util::*;
static UTIL_NAME: &'static str = "wc";

69
tests/tests.rs Normal file
View file

@ -0,0 +1,69 @@
extern crate filetime;
extern crate libc;
extern crate rand;
extern crate regex;
extern crate tempdir;
extern crate time;
extern crate uu_tail;
#[cfg(windows)] extern crate kernel32;
#[cfg(windows)] extern crate winapi;
#[macro_use]
mod common;
#[path="../src/factor/sieve.rs"]
mod sieve;
#[cfg(unix)] mod test_chmod;
#[cfg(unix)] mod test_mv;
#[cfg(unix)] mod test_stdbuf;
#[cfg(unix)] mod test_touch;
#[cfg(unix)] mod test_unlink;
mod test_base64;
mod test_basename;
mod test_cat;
mod test_cksum;
mod test_comm;
mod test_cp;
mod test_cut;
mod test_dircolors;
mod test_dirname;
mod test_echo;
mod test_env;
mod test_expr;
mod test_factor;
mod test_false;
mod test_fold;
mod test_hashsum;
mod test_head;
mod test_link;
mod test_ln;
mod test_ls;
mod test_mkdir;
mod test_mktemp;
mod test_nl;
mod test_od;
mod test_paste;
mod test_printf;
mod test_ptx;
mod test_pwd;
mod test_readlink;
mod test_realpath;
mod test_rm;
mod test_rmdir;
mod test_seq;
mod test_sort;
mod test_split;
mod test_sum;
mod test_tac;
mod test_tail;
mod test_test;
mod test_tr;
mod test_true;
mod test_truncate;
mod test_tsort;
mod test_unexpand;
mod test_uniq;
mod test_wc;