mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
fix test
This commit is contained in:
parent
1c93a793e9
commit
cab4f8d570
3 changed files with 23 additions and 13 deletions
|
@ -39,7 +39,11 @@ fn main() {
|
||||||
util_map.push_str("map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n");
|
util_map.push_str("map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n");
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]);
|
if prog == "test" {
|
||||||
|
crates.push_str(&(format!("extern crate uu{0} as uu{0};\n", prog))[..]);
|
||||||
|
} else {
|
||||||
|
crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]);
|
||||||
|
}
|
||||||
util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> i32);\n", prog = prog))[..]);
|
util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> i32);\n", prog = prog))[..]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "test"]
|
#![crate_name = "test"]
|
||||||
#![feature(core, os, std_misc)]
|
#![feature(convert)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,16 +13,16 @@
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::CString;
|
use std::ffi::{CString, OsString};
|
||||||
use std::os::{args_as_bytes};
|
use std::env::{args_os};
|
||||||
use std::str::{from_utf8};
|
use std::str::{from_utf8};
|
||||||
|
|
||||||
static NAME: &'static str = "test";
|
static NAME: &'static str = "test";
|
||||||
|
|
||||||
// TODO: decide how to handle non-UTF8 input for all the utils
|
// TODO: decide how to handle non-UTF8 input for all the utils
|
||||||
pub fn uumain(_: Vec<String>) -> i32 {
|
pub fn uumain(_: Vec<String>) -> i32 {
|
||||||
let args = args_as_bytes();
|
let args = args_os().collect::<Vec<OsString>>();
|
||||||
let args: Vec<&[u8]> = args.iter().map(|a| a.as_slice()).collect();
|
let args = args.iter().map(|a| a.to_bytes().unwrap()).collect::<Vec<&[u8]>>();
|
||||||
if args.len() == 0 {
|
if args.len() == 0 {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ pub fn uumain(_: Vec<String>) -> i32 {
|
||||||
if !args[0].ends_with(NAME.as_bytes()) {
|
if !args[0].ends_with(NAME.as_bytes()) {
|
||||||
&args[1..]
|
&args[1..]
|
||||||
} else {
|
} else {
|
||||||
args.as_slice()
|
&args[..]
|
||||||
};
|
};
|
||||||
let args = match args[0] {
|
let args = match args[0] {
|
||||||
b"[" => match args[args.len() - 1] {
|
b"[" => match args[args.len() - 1] {
|
||||||
|
@ -83,6 +83,7 @@ fn two(args: &[&[u8]], error: &mut bool) -> bool {
|
||||||
fn three(args: &[&[u8]], error: &mut bool) -> bool {
|
fn three(args: &[&[u8]], error: &mut bool) -> bool {
|
||||||
match args[1] {
|
match args[1] {
|
||||||
b"=" => args[0] == args[2],
|
b"=" => args[0] == args[2],
|
||||||
|
b"==" => args[0] == args[2],
|
||||||
b"!=" => args[0] != args[2],
|
b"!=" => args[0] != args[2],
|
||||||
b"-eq" => integers(args[0], args[2], IntegerCondition::Equal),
|
b"-eq" => integers(args[0], args[2], IntegerCondition::Equal),
|
||||||
b"-ne" => integers(args[0], args[2], IntegerCondition::Unequal),
|
b"-ne" => integers(args[0], args[2], IntegerCondition::Unequal),
|
||||||
|
@ -191,6 +192,7 @@ fn dispatch_four(args: &mut &[&[u8]], error: &mut bool) -> (bool, usize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
enum Precedence {
|
enum Precedence {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
Paren, // FIXME: this is useless (parentheses have not been implemented)
|
Paren, // FIXME: this is useless (parentheses have not been implemented)
|
||||||
|
@ -201,8 +203,6 @@ enum Precedence {
|
||||||
UnOp
|
UnOp
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Copy for Precedence {}
|
|
||||||
|
|
||||||
fn parse_expr(mut args: &[&[u8]], error: &mut bool) -> bool {
|
fn parse_expr(mut args: &[&[u8]], error: &mut bool) -> bool {
|
||||||
if args.len() == 0 {
|
if args.len() == 0 {
|
||||||
false
|
false
|
||||||
|
|
14
test/test.rs
14
test/test.rs
|
@ -1,6 +1,13 @@
|
||||||
#![allow(unstable)]
|
/*
|
||||||
|
* This file is part of the uutils coreutils package.
|
||||||
|
*
|
||||||
|
* (c) mahkoh (ju.orth [at] gmail [dot] com)
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
use std::old_io::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
static EXE: &'static str = "./test";
|
static EXE: &'static str = "./test";
|
||||||
|
|
||||||
|
@ -26,6 +33,5 @@ fn test_op_prec_and_or_2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_or_as_filename() {
|
fn test_or_as_filename() {
|
||||||
let status = Command::new(EXE).arg("x").arg("-a").arg("-z").arg("-o").status();
|
let status = Command::new(EXE).arg("x").arg("-a").arg("-z").arg("-o").status();
|
||||||
assert!(status.unwrap().matches_exit_status(1));
|
assert_eq!(status.unwrap().code(), Some(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue