mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 12:24:09 +00:00
Move tests out of src and into test
This commit is contained in:
parent
b7f4bd01bc
commit
439a8cadd1
25
Makefile
25
Makefile
|
@ -25,9 +25,13 @@ endif
|
|||
PREFIX ?= /usr/local
|
||||
BINDIR ?= /bin
|
||||
|
||||
BASEDIR ?= .
|
||||
# This won't support any directory with spaces in its name, but you can just
|
||||
# make a symlink without spaces that points to the directory.
|
||||
BASEDIR ?= $(shell pwd)
|
||||
SRCDIR := $(BASEDIR)/src
|
||||
BUILDDIR := $(BASEDIR)/build
|
||||
TESTDIR := $(BASEDIR)/test
|
||||
TEMPDIR := $(BASEDIR)/tmp
|
||||
|
||||
# Possible programs
|
||||
PROGS := \
|
||||
|
@ -178,11 +182,14 @@ endef
|
|||
|
||||
# Test exe built rules
|
||||
define TEST_BUILD
|
||||
test_$(1): tmp/$(1)_test $(BUILDDIR)/$(1)
|
||||
$(call command,$$<)
|
||||
test_$(1): $(TEMPDIR)/$(1)/$(1)_test $(BUILDDIR)/$(1)
|
||||
$(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<)
|
||||
|
||||
tmp/$(1)_test: $(SRCDIR)/$(1)/test.rs
|
||||
$(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1)
|
||||
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o $$@ $$<)
|
||||
|
||||
$(TEMPDIR)/$(1): | $(TEMPDIR)
|
||||
$(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@)
|
||||
endef
|
||||
|
||||
# Main rules
|
||||
|
@ -220,18 +227,18 @@ deps: $(BUILDDIR)/.rust-crypto $(SRCDIR)/cksum/crc_table.rs
|
|||
crates:
|
||||
echo $(EXES)
|
||||
|
||||
test: tmp $(addprefix test_,$(TESTS))
|
||||
$(RM) -rf tmp
|
||||
test: $(TEMPDIR) $(addprefix test_,$(TESTS))
|
||||
$(RM) -rf $(TEMPDIR)
|
||||
|
||||
clean:
|
||||
$(RM) -rf $(BUILDDIR) tmp
|
||||
$(RM) -rf $(BUILDDIR) $(TEMPDIR)
|
||||
|
||||
$(BUILDDIR):
|
||||
git submodule update --init
|
||||
mkdir -p $(BUILDDIR)/gen
|
||||
|
||||
tmp:
|
||||
mkdir tmp
|
||||
$(TEMPDIR):
|
||||
mkdir $(TEMPDIR)
|
||||
|
||||
install: $(addprefix $(BUILDDIR)/,$(INSTALLEES))
|
||||
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use std::io::process::Command;
|
||||
use std::str;
|
||||
|
||||
static PROGNAME: &'static str = "./cat";
|
||||
|
||||
#[test]
|
||||
fn test_output_multi_files_print_all_chars() {
|
||||
let po = match Command::new("build/cat")
|
||||
.arg("src/cat/fixtures/alpha.txt")
|
||||
.arg("src/cat/fixtures/256.txt")
|
||||
let po = match Command::new(PROGNAME)
|
||||
.arg("alpha.txt")
|
||||
.arg("256.txt")
|
||||
.arg("-A")
|
||||
.arg("-n").output() {
|
||||
|
||||
|
@ -20,7 +22,7 @@ fn test_output_multi_files_print_all_chars() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_squeeze() {
|
||||
let mut process= Command::new("build/cat").arg("-A").spawn().unwrap();
|
||||
let mut process= Command::new(PROGNAME).arg("-A").spawn().unwrap();
|
||||
|
||||
process.stdin.take_unwrap().write(b"\x00\x01\x02").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
|
@ -31,7 +33,7 @@ fn test_stdin_squeeze() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
let mut process = Command::new("build/cat").arg("-b").arg("-").spawn().unwrap();
|
||||
let mut process = Command::new(PROGNAME).arg("-b").arg("-").spawn().unwrap();
|
||||
|
||||
process.stdin.take_unwrap().write(b"\na\nb\n\n\nc").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
|
@ -1,12 +1,12 @@
|
|||
use std::io::process::Command;
|
||||
use std::io::fs::rmdir;
|
||||
|
||||
static exe: &'static str = "build/mkdir";
|
||||
static test_dir1: &'static str = "tmp/mkdir_test1";
|
||||
static test_dir2: &'static str = "tmp/mkdir_test2";
|
||||
static test_dir3: &'static str = "tmp/mkdir_test3";
|
||||
static test_dir4: &'static str = "tmp/mkdir_test4/mkdir_test4_1";
|
||||
static test_dir5: &'static str = "tmp/mkdir_test5/mkdir_test5_1";
|
||||
static exe: &'static str = "./mkdir";
|
||||
static test_dir1: &'static str = "mkdir_test1";
|
||||
static test_dir2: &'static str = "mkdir_test2";
|
||||
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";
|
||||
|
||||
fn cleanup(dir: &'static str) {
|
||||
let d = dir.into_string();
|
|
@ -1,10 +1,11 @@
|
|||
use std::io::process::Command;
|
||||
use std::str;
|
||||
|
||||
static PROGNAME: &'static str = "./nl";
|
||||
|
||||
#[test]
|
||||
fn test_stdin_nonewline() {
|
||||
|
||||
let mut process = Command::new("build/nl").spawn().unwrap();
|
||||
let mut process = Command::new(PROGNAME).spawn().unwrap();
|
||||
process.stdin.take_unwrap().write(b"No Newline").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
@ -13,8 +14,7 @@ fn test_stdin_nonewline() {
|
|||
}
|
||||
#[test]
|
||||
fn test_stdin_newline() {
|
||||
|
||||
let mut process = Command::new("build/nl").arg("-s").arg("-")
|
||||
let mut process = Command::new(PROGNAME).arg("-s").arg("-")
|
||||
.arg("-w").arg("1").spawn().unwrap();
|
||||
|
||||
process.stdin.take_unwrap().write(b"Line One\nLine Two\n").unwrap();
|
||||
|
@ -26,8 +26,8 @@ fn test_stdin_newline() {
|
|||
|
||||
#[test]
|
||||
fn test_padding_without_overflow() {
|
||||
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
||||
.arg("-n").arg("rz").arg("src/nl/fixtures/simple.txt").output().unwrap();
|
||||
let po = Command::new(PROGNAME).arg("-i").arg("1000").arg("-s").arg("x")
|
||||
.arg("-n").arg("rz").arg("simple.txt").output().unwrap();
|
||||
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n007001xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014001xL15\n");
|
||||
|
@ -35,9 +35,9 @@ fn test_padding_without_overflow() {
|
|||
|
||||
#[test]
|
||||
fn test_padding_with_overflow() {
|
||||
let po = Command::new("build/nl").arg("-i").arg("1000").arg("-s").arg("x")
|
||||
let po = Command::new(PROGNAME).arg("-i").arg("1000").arg("-s").arg("x")
|
||||
.arg("-n").arg("rz").arg("-w").arg("4")
|
||||
.arg("src/nl/fixtures/simple.txt").output().unwrap();
|
||||
.arg("simple.txt").output().unwrap();
|
||||
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n");
|
||||
|
@ -47,15 +47,15 @@ fn test_padding_with_overflow() {
|
|||
fn test_sections_and_styles() {
|
||||
for &(fixture, output) in [
|
||||
(
|
||||
"src/nl/fixtures/section.txt",
|
||||
"section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"
|
||||
),
|
||||
(
|
||||
"src/nl/fixtures/joinblanklines.txt",
|
||||
"joinblanklines.txt",
|
||||
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 |Nonempty.\n"
|
||||
),
|
||||
].iter() {
|
||||
let po = Command::new("build/nl").arg("-s").arg("|").arg("-n").arg("ln")
|
||||
let po = Command::new(PROGNAME).arg("-s").arg("|").arg("-n").arg("ln")
|
||||
.arg("-w").arg("3").arg("-b").arg("a").arg("-l").arg("5")
|
||||
.arg(fixture).output().unwrap();
|
||||
assert_eq!(str::from_utf8(po.output.as_slice()).unwrap(), output);
|
|
@ -1,30 +1,32 @@
|
|||
use std::io::process::Command;
|
||||
use std::str;
|
||||
|
||||
static PROGNAME: &'static str = "./seq";
|
||||
|
||||
#[test]
|
||||
fn test_count_up() {
|
||||
let p = Command::new("build/seq").args(["10"]).output().unwrap();
|
||||
let p = Command::new(PROGNAME).args(["10"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count_down() {
|
||||
let p = Command::new("build/seq").args(["--", "5", "-1", "1"]).output().unwrap();
|
||||
let p = Command::new(PROGNAME).args(["--", "5", "-1", "1"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "5\n4\n3\n2\n1\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_separator_and_terminator() {
|
||||
let p = Command::new("build/seq").args(["-s", ",", "-t", "!", "2", "6"]).output().unwrap();
|
||||
let p = Command::new(PROGNAME).args(["-s", ",", "-t", "!", "2", "6"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "2,3,4,5,6!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equalize_widths() {
|
||||
let p = Command::new("build/seq").args(["-w", "5", "10"]).output().unwrap();
|
||||
let p = Command::new(PROGNAME).args(["-w", "5", "10"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "05\n06\n07\n08\n09\n10\n");
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
use std::io::process::Command;
|
||||
|
||||
static PROGNAME: &'static str = "./tr";
|
||||
|
||||
fn run(input: &str, args: &[&'static str]) -> Vec<u8> {
|
||||
let mut process = Command::new("build/tr").args(args).spawn().unwrap();
|
||||
let mut process = Command::new(PROGNAME).args(args).spawn().unwrap();
|
||||
|
||||
process.stdin.take_unwrap().write_str(input).unwrap();
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
use std::io;
|
||||
use std::io::process::Command;
|
||||
|
||||
static PROG: &'static str = "build/truncate";
|
||||
static PROGNAME: &'static str = "./truncate";
|
||||
static TFILE1: &'static str = "truncate_test_1";
|
||||
static TFILE2: &'static str = "truncate_test_2";
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn make_file(name: &str) -> io::File {
|
|||
#[test]
|
||||
fn test_increase_file_size() {
|
||||
let mut file = make_file(TFILE1);
|
||||
if !Command::new(PROG).args(["-s", "+5K", TFILE1]).status().unwrap().success() {
|
||||
if !Command::new(PROGNAME).args(["-s", "+5K", TFILE1]).status().unwrap().success() {
|
||||
fail!();
|
||||
}
|
||||
file.seek(0, io::SeekEnd).unwrap();
|
||||
|
@ -29,7 +29,7 @@ fn test_increase_file_size() {
|
|||
fn test_decrease_file_size() {
|
||||
let mut file = make_file(TFILE2);
|
||||
file.write(b"1234567890").unwrap();
|
||||
if !Command::new(PROG).args(["--size=-4", TFILE2]).status().unwrap().success() {
|
||||
if !Command::new(PROGNAME).args(["--size=-4", TFILE2]).status().unwrap().success() {
|
||||
fail!();
|
||||
}
|
||||
file.seek(0, io::SeekEnd).unwrap();
|
Loading…
Reference in a new issue