From b76ff8fd90bba9e4a93178622b92f0dd398e9bd8 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 9 Aug 2024 23:50:31 -0600 Subject: [PATCH] tests, Makefile: cleaning up --- Makefile | 4 ++-- src/hru.rs | 6 +++++- tests/bonsai/fop.mk | 2 +- tests/bonsai/hru.mk | 9 +++++---- tests/bonsai/mm.mk | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 5db506e..87bf566 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,8 @@ dist: all docs install: dist cp -r $(DESTDIR)/* / +include tests/tests.mk + .PHONY: test test: all $(TESTS) /tmp/getopt @echo $(TESTS) @@ -156,5 +158,3 @@ build/bin/swab: src/swab.rs build rustlibs true: build/bin/true build/bin/true: src/true.c build $(CC) $(CFLAGS) -o $@ src/true.c - -include tests/tests.mk diff --git a/src/hru.rs b/src/hru.rs index c02d4c1..1ed5bdd 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -27,7 +27,7 @@ extern crate strerror; extern crate sysexits; use strerror::StrError; -use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; +use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE, EX_USAGE }; /* list of SI prefixes */ const LIST: [(u32, &str); 10] = [ @@ -76,6 +76,10 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> { fn main() -> ExitCode { let argv = args().collect::>(); + if let Some(_) = argv.get(1) { + eprintln!("Usage: {}", argv[0]); + return ExitCode::from(EX_USAGE as u8); + } let mut buf = String::new(); while let Ok(_) = stdin().read_line(&mut buf) { diff --git a/tests/bonsai/fop.mk b/tests/bonsai/fop.mk index 9013308..b538031 100755 --- a/tests/bonsai/fop.mk +++ b/tests/bonsai/fop.mk @@ -14,7 +14,7 @@ fop_help: $(BIN)/fop .PHONY: fop_delimiter fop_delimiter: $(BIN)/fop - test "$$(printf 'test1 test1 test1\n' | $(BIN)/fop -d' ' 2 sed 's/2/4/g')" \ + test "$$(printf 'test1 test1 test1\n' | $(BIN)/fop -d' ' 2 sed 's/1/4/g')" \ = 'test1 test1 test4' test "$$(printf 'meowsetwoofsetribbit\n' \ | $(BIN)/fop -d 'set' 1 sed 's/woof/meow/g')" = 'meowsetmeowsetribbit' diff --git a/tests/bonsai/hru.mk b/tests/bonsai/hru.mk index 6f3a05f..49d30cd 100755 --- a/tests/bonsai/hru.mk +++ b/tests/bonsai/hru.mk @@ -6,7 +6,7 @@ # notice are preserved. This file is offered as-is, without any warranty. .PHONY: hru_tests -hru_tests: hru_help hru_functionality hru_negative hru_regression +hru_tests: hru_help hru_functionality hru_negative hru_regressions .PHONY: hru_help hru_help: $(BIN)/hru @@ -14,8 +14,8 @@ hru_help: $(BIN)/hru .PHONY: hru_functionality hru_functionality: $(BIN)/hru - test "$(printf '1234\n' | $(BIN)/hru)" = '1.2 kB' - test "$(printf '0\n' | $(BIN)/hru)" = '0 B' + test "$$(printf '1234\n' | $(BIN)/hru)" = '1.2 kB' + test "$$(printf '0\n' | $(BIN)/hru)" = '0 B' .PHONY: hru_negative hru_negative: $(BIN)/hru @@ -25,7 +25,8 @@ hru_negative: $(BIN)/hru hru_regressions: $(BIN)/hru n=1; \ while true; \ - do n="$$(($$n * 10))"; \ + do \ printf '%s\n' "$$n" | $(BIN)/hru || break; \ + n="$$(($$n * 10))"; \ done; \ printf 'Max float: %s\n' "$$n" diff --git a/tests/bonsai/mm.mk b/tests/bonsai/mm.mk index 6117330..2b1fea6 100755 --- a/tests/bonsai/mm.mk +++ b/tests/bonsai/mm.mk @@ -24,4 +24,4 @@ mm_help: $(BIN)/mm .PHONY: mm_stderr # check if stderr is empty upon specifying -e mm_stderr: $(BIN)/mm - ! test "$$(printf 'test\n' | $(BIN)/mm -i - -e 2>&1 >/dev/null)" = "test" + ! test "$$(printf 'test\n' | $(BIN)/mm -e 2>&1 >/dev/null)" = "test"