aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c6
-rw-r--r--tests/justify.bats7
2 files changed, 11 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 7671bd6..8ed128c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,16 +17,18 @@ void print_usage(const char *prog) {
int main(int argc, char *argv[]) {
int opt;
+ int width;
size_t linebuffer_capacity = DEFAULT_LINEBUFFER_CAPACITY;
while ((opt = getopt(argc, argv, "w:h")) != -1) {
switch (opt) {
case 'w':
- linebuffer_capacity = (size_t)atoi(optarg);
- if (linebuffer_capacity == 0) {
+ width = atoi(optarg);
+ if (width <= 0) {
print_usage(argv[0]);
return EXIT_FAILURE;
}
+ linebuffer_capacity= (size_t) width;
break;
case 'h':
default:
diff --git a/tests/justify.bats b/tests/justify.bats
index 86ae4df..6b7a275 100644
--- a/tests/justify.bats
+++ b/tests/justify.bats
@@ -6,6 +6,13 @@ load 'vendor/bats-file/load'
JUSTIFY_BIN="./build/justify"
+@test "-w should reject invalid values" {
+ run "${JUSTIFY_BIN}" -w 0
+ assert_failure
+ run "${JUSTIFY_BIN}" -w -1
+ assert_failure
+}
+
@test "last line of the output is left aligned" {
run "${JUSTIFY_BIN}" <<EOF
This is a test of the emergency broadcast system.