Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
2bd7006d7a
|
|||
|
4c36ec1807
|
|||
|
c01af89e52
|
|||
|
73b84f9719
|
|||
|
383d53168f
|
|||
|
7a452794b1
|
|||
|
7142994367
|
|||
|
eb454a6dad
|
|||
|
9c1e0d785d
|
|||
|
68919bf877
|
|||
|
ea8b58554e
|
|||
|
e26d8e0e1b
|
@@ -99,10 +99,9 @@ their editor or terminal.
|
|||||||
|
|
||||||
For usage text and help messages, do not implement a -h option. Instead, print
|
For usage text and help messages, do not implement a -h option. Instead, print
|
||||||
usage information when any erroneous option is specified. Follow the NetBSD
|
usage information when any erroneous option is specified. Follow the NetBSD
|
||||||
style guide for the usage text’s output format [0].
|
style guide for the usage text’s output format [1].
|
||||||
|
|
||||||
If committing a new utility, please include tests and documentation (see
|
[1] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
||||||
tests/ and docs/) for the new tool.
|
|
||||||
|
|
||||||
If committing a new source file, format the commit message following these
|
If committing a new source file, format the commit message following these
|
||||||
guidelines:
|
guidelines:
|
||||||
@@ -131,7 +130,6 @@ $ git commit -m 'tool(1): fix #42 & add feature x'
|
|||||||
|
|
||||||
Commit messages should be written in the present tense.
|
Commit messages should be written in the present tense.
|
||||||
|
|
||||||
[0] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
|
||||||
--
|
--
|
||||||
This work © 2023–2024 by Emma Tebibyte is licensed under CC BY-SA 4.0. To view a
|
This work © 2023–2024 by Emma Tebibyte is licensed under CC BY-SA 4.0. To view a
|
||||||
copy of this license, visit <http://creativecommons.org/licenses/by-sa/4.0/>
|
copy of this license, visit <http://creativecommons.org/licenses/by-sa/4.0/>
|
||||||
|
|||||||
38
Makefile
38
Makefile
@@ -17,27 +17,22 @@ DESTDIR ?= dist
|
|||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
# normalized prefix
|
# normalized prefix
|
||||||
PREFIX_N != dirname $(PREFIX)/.
|
PREFIX_N != (test -d $(PREFIX) && [ '-' != $(PREFIX) ] \
|
||||||
MANDIR != test $(PREFIX_N) = / && printf '/usr/share/man\n' \
|
&& CDPATH= cd -P -- $(PREFIX) && pwd -P)
|
||||||
|
MANDIR != [ $(PREFIX_N) = / ] && printf '/usr/share/man\n' \
|
||||||
|| printf '/share/man\n'
|
|| printf '/share/man\n'
|
||||||
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | tr ' ' '\n' \
|
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | tr ' ' '\n' \
|
||||||
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
||||||
|
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
RUSTC ?= rustc
|
RUSTC ?= rustc
|
||||||
RUSTFLAGS += --extern getopt=build/o/libgetopt.rlib \
|
RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
||||||
--extern sysexits=build/o/libsysexits.rlib \
|
--extern sysexits=build/o/libsysexits.rlib \
|
||||||
--extern strerror=build/o/libstrerror.rlib
|
--extern strerror=build/o/libstrerror.rlib
|
||||||
CFLAGS += -I$(SYSEXITS)
|
CFLAGS += -I$(SYSEXITS)
|
||||||
|
|
||||||
# testing requires the absolute path to the bin directory set
|
|
||||||
BIN = build/bin
|
|
||||||
|
|
||||||
.PHONY: default
|
|
||||||
default: all test
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
|
all: dj false fop hru intcmp mm npc rpn scroll scrut str strcmp swab true
|
||||||
|
|
||||||
# keep build/include until bindgen(1) has stdin support
|
# keep build/include until bindgen(1) has stdin support
|
||||||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
||||||
@@ -57,12 +52,10 @@ dist: all docs
|
|||||||
install: dist
|
install: dist
|
||||||
cp -r $(DESTDIR)/* /
|
cp -r $(DESTDIR)/* /
|
||||||
|
|
||||||
include tests/tests.mk
|
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all $(TESTS) /tmp/getopt
|
test: build /tmp/getopt
|
||||||
@echo $(TESTS)
|
|
||||||
/tmp/getopt
|
/tmp/getopt
|
||||||
|
tests/posix-compat.sh
|
||||||
|
|
||||||
/tmp/getopt: src/libgetopt.rs
|
/tmp/getopt: src/libgetopt.rs
|
||||||
$(RUSTC) --test -o /tmp/getopt src/libgetopt.rs
|
$(RUSTC) --test -o /tmp/getopt src/libgetopt.rs
|
||||||
@@ -107,32 +100,37 @@ build/bin/false: src/false.c build
|
|||||||
.PHONY: fop
|
.PHONY: fop
|
||||||
fop: build/bin/fop
|
fop: build/bin/fop
|
||||||
build/bin/fop: src/fop.rs build rustlibs
|
build/bin/fop: src/fop.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/fop.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/fop.rs
|
||||||
|
|
||||||
.PHONY: hru
|
.PHONY: hru
|
||||||
hru: build/bin/hru
|
hru: build/bin/hru
|
||||||
build/bin/hru: src/hru.rs build rustlibs
|
build/bin/hru: src/hru.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/hru.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/hru.rs
|
||||||
|
|
||||||
.PHONY: intcmp
|
.PHONY: intcmp
|
||||||
intcmp: build/bin/intcmp
|
intcmp: build/bin/intcmp
|
||||||
build/bin/intcmp: src/intcmp.rs build rustlibs
|
build/bin/intcmp: src/intcmp.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/intcmp.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/intcmp.rs
|
||||||
|
|
||||||
.PHONY: mm
|
.PHONY: mm
|
||||||
mm: build/bin/mm
|
mm: build/bin/mm
|
||||||
build/bin/mm: src/mm.rs build rustlibs
|
build/bin/mm: src/mm.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/mm.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/mm.rs
|
||||||
|
|
||||||
.PHONY: npc
|
.PHONY: npc
|
||||||
npc: build/bin/npc
|
npc: build/bin/npc
|
||||||
build/bin/npc: src/npc.c build
|
build/bin/npc: src/npc.c build
|
||||||
$(CC) $(CFLAGS) -o $@ src/npc.c
|
$(CC) $(CFLAGS) -o $@ src/npc.c
|
||||||
|
|
||||||
|
.PHONY: scroll
|
||||||
|
scroll: build/bin/scroll
|
||||||
|
build/bin/scroll: src/scroll.c build
|
||||||
|
$(CC) $(CFLAGS) -o $@ src/scroll.c
|
||||||
|
|
||||||
.PHONY: rpn
|
.PHONY: rpn
|
||||||
rpn: build/bin/rpn
|
rpn: build/bin/rpn
|
||||||
build/bin/rpn: src/rpn.rs build rustlibs
|
build/bin/rpn: src/rpn.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/rpn.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/rpn.rs
|
||||||
|
|
||||||
.PHONY: scrut
|
.PHONY: scrut
|
||||||
scrut: build/bin/scrut
|
scrut: build/bin/scrut
|
||||||
@@ -152,7 +150,7 @@ build/bin/strcmp: src/strcmp.c build
|
|||||||
.PHONY: swab
|
.PHONY: swab
|
||||||
swab: build/bin/swab
|
swab: build/bin/swab
|
||||||
build/bin/swab: src/swab.rs build rustlibs
|
build/bin/swab: src/swab.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/swab.rs
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/swab.rs
|
||||||
|
|
||||||
.PHONY: true
|
.PHONY: true
|
||||||
true: build/bin/true
|
true: build/bin/true
|
||||||
|
|||||||
52
docs/scroll.1
Normal file
52
docs/scroll.1
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
|
.\" Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
.\"
|
||||||
|
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||||
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
|
.\"
|
||||||
|
.TH PG 1 2024-07-31 "Harakit X.X.X"
|
||||||
|
.SH NAME
|
||||||
|
scroll \(en present output
|
||||||
|
.\"
|
||||||
|
.SH SYNOPSIS
|
||||||
|
|
||||||
|
scroll
|
||||||
|
.RB ( -p
|
||||||
|
.RB [ prompt ])
|
||||||
|
.\"
|
||||||
|
.SH DESCRIPTION
|
||||||
|
|
||||||
|
Print standard input to standard output, accepting commands between pages.
|
||||||
|
.\"
|
||||||
|
.SH OPTIONS
|
||||||
|
|
||||||
|
.IP -p
|
||||||
|
Replace the default prompt (\(lq: \(rq) with the option argument.
|
||||||
|
.\"
|
||||||
|
.SH DIAGNOSTICS
|
||||||
|
|
||||||
|
In the event of an error, a debug message will be printed and the program will
|
||||||
|
exit with the appropriate
|
||||||
|
.BR sysexits.h (3)
|
||||||
|
error code.
|
||||||
|
.\"
|
||||||
|
.SH RATIONALE
|
||||||
|
|
||||||
|
Plan 9 from Bell Labs had
|
||||||
|
.BR p (1),
|
||||||
|
a similar \(lqcooked\(rq-mode paginator (as opposed to \(lqraw\(rq mode, which a
|
||||||
|
vast majority of paginators use).
|
||||||
|
.\"
|
||||||
|
.SH AUTHOR
|
||||||
|
|
||||||
|
Written by DTB
|
||||||
|
.MT trinity@trinity.moe
|
||||||
|
.ME .
|
||||||
|
.\"
|
||||||
|
.SH COPYRIGHT
|
||||||
|
|
||||||
|
Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||||
|
<https://gnu.org/licenses/agpl.html>.
|
||||||
|
.\"
|
||||||
|
.SH SEE ALSO
|
||||||
|
.BR more (1p)
|
||||||
@@ -33,7 +33,6 @@ line:
|
|||||||
.RS
|
.RS
|
||||||
printf 'hello world!\(rsn' | swab
|
printf 'hello world!\(rsn' | swab
|
||||||
.RE
|
.RE
|
||||||
.\" If you change this, make sure to change it in tests/bonsai/swab.mk too.
|
|
||||||
|
|
||||||
Produces the following output:
|
Produces the following output:
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ extern crate strerror;
|
|||||||
extern crate sysexits;
|
extern crate sysexits;
|
||||||
|
|
||||||
use strerror::StrError;
|
use strerror::StrError;
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE, EX_USAGE };
|
use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE };
|
||||||
|
|
||||||
/* list of SI prefixes */
|
/* list of SI prefixes */
|
||||||
const LIST: [(u32, &str); 10] = [
|
const LIST: [(u32, &str); 10] = [
|
||||||
@@ -76,10 +76,6 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
|
|||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
if let Some(_) = argv.get(1) {
|
|
||||||
eprintln!("Usage: {}", argv[0]);
|
|
||||||
return ExitCode::from(EX_USAGE as u8);
|
|
||||||
}
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
while let Ok(_) = stdin().read_line(&mut buf) {
|
while let Ok(_) = stdin().read_line(&mut buf) {
|
||||||
|
|||||||
288
src/scroll.c
Normal file
288
src/scroll.c
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU Affero General Public License as published by the Free
|
||||||
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h> /* assert(3) */
|
||||||
|
#include <errno.h> /* errno */
|
||||||
|
#include <stdbool.h> /* bool */
|
||||||
|
#include <stdio.h> /* fclose(3), feof(3), fgetc(3), fgets(3), fopen(3),
|
||||||
|
* fprintf(3), fputc(3), perror(3), stderr, stdin, stdout,
|
||||||
|
* EOF, FILE, NULL */
|
||||||
|
#include <stdlib.h> /* size_t */
|
||||||
|
#include <string.h> /* strchr(3), strcmp(3) */
|
||||||
|
#include <unistd.h> /* getopt(3) */
|
||||||
|
|
||||||
|
/* Commands start with cmd_. They take an argc and NULL-terminated argv, like
|
||||||
|
* main, and return a status from <sysexits.h>. Return values other than EX_OK
|
||||||
|
* and EX_USAGE cause pg(1) to exit with that value, except EX_UNAVAILABLE,
|
||||||
|
* which causes pg(1) to exit with the status EX_OK. */
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
|
#define CMDLINE_MAX 99+1 /* Maximum length of command line. */
|
||||||
|
|
||||||
|
static char *whitespace = " \n\r\t\v";
|
||||||
|
|
||||||
|
//static
|
||||||
|
struct Tube {
|
||||||
|
char *name; // command line
|
||||||
|
FILE *in; // process stdin
|
||||||
|
FILE *out; // process stdoout
|
||||||
|
size_t index; // in pipeline
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
size_t quantity;
|
||||||
|
enum { LINES = 0, BYTES = 1 } type;
|
||||||
|
} default_page_unit = { 22, LINES } /* Plan 9 default */;
|
||||||
|
|
||||||
|
static char *prompt = ": ";
|
||||||
|
static char *program_name = "pg";
|
||||||
|
|
||||||
|
static char *
|
||||||
|
permute_out(char *s, size_t i) {
|
||||||
|
for (
|
||||||
|
;
|
||||||
|
s[i] != '\0';
|
||||||
|
s[i] = s[i + 1], ++i
|
||||||
|
);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* strtok(3p), but supports double-quotes and escapes (but only for escaping
|
||||||
|
* quotes). Unmatched quotes in str are considered literal. The behavior of
|
||||||
|
* strtok_quoted when '\'', '"', or '\\' are in sep is undefined. Use of UTF-8
|
||||||
|
* separators with strtok_quoted is undefined. */
|
||||||
|
static char *
|
||||||
|
strtok_quoted(char *str, char *sep) {
|
||||||
|
static char *s;
|
||||||
|
|
||||||
|
if (str != NULL) { s = str; }
|
||||||
|
|
||||||
|
while (strchr(sep, *s) != NULL) { // skip beginning whitespace
|
||||||
|
if(*++s == '\0') { return NULL; } // no remaining except seps
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
bool in_escape = 0; // previous char was '\\'
|
||||||
|
char quote = '\0'; // quotation mark used, or '\0' if none
|
||||||
|
|
||||||
|
for (int i = 0; s[i] != '\0'; ++i)
|
||||||
|
switch (s[i]) {
|
||||||
|
case '\\':
|
||||||
|
// if literal "\\", permute out a backslash
|
||||||
|
if (in_escape) { (void)permute_out(s, i--); }
|
||||||
|
in_escape = !in_escape;
|
||||||
|
break;
|
||||||
|
case '\'': case '"':
|
||||||
|
if (in_escape) { // \"
|
||||||
|
s[i] = s[i - 1];
|
||||||
|
(void)permute_out(s, i--); // permute out backslash
|
||||||
|
} else if (s[i] == quote) {
|
||||||
|
quote = '\0';
|
||||||
|
(void)permute_out(s, i--); // second quote
|
||||||
|
} else {
|
||||||
|
quote = s[i];
|
||||||
|
if (strchr(&s[i + 1], quote) != NULL) { // has a match
|
||||||
|
(void)permute_out(s, i--); // permute out lquote
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\0': return s;
|
||||||
|
default:
|
||||||
|
if (!in_escape
|
||||||
|
&& quote == '\0'
|
||||||
|
&& (strchr(sep, s[i]) != NULL || s[i] == '\0')) {
|
||||||
|
char *t; // start of current token
|
||||||
|
|
||||||
|
t = s;
|
||||||
|
s = s[i] != '\0'
|
||||||
|
? &t[i + 1] // store start of next token,
|
||||||
|
: &t[i]; // or the address of the nul if found
|
||||||
|
s[i] = '\0'; // NUL terminate current token
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page at most l bytes from f without consideration of a buffer (print them to
|
||||||
|
* stdout). */
|
||||||
|
static int
|
||||||
|
pg_b_u(FILE *f, size_t l) {
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = fgetc(f)) != EOF) {
|
||||||
|
if ((c = fputc(c, stdout)) == EOF || --l == 0) { break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page at most l lines, which are lengths of characters terminated by nl, from
|
||||||
|
* f without consideration of a buffer (print them to stdout). */
|
||||||
|
static int
|
||||||
|
pg_l_u(FILE *f, size_t l, char nl) {
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = fgetc(f)) != EOF) {
|
||||||
|
if ((c = fputc(c, stdout)) == EOF || (l -= (c == nl)) == 0) { break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmd_quit(int argc, char **argv, char **envp) { return EX_UNAVAILABLE; }
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmd_default_page(int argc, char **argv, char **envp) {
|
||||||
|
if (argc > 1) { return EX_USAGE; } // should be impossible
|
||||||
|
else if (default_page_unit.type == BYTES) {
|
||||||
|
return pg_b_u(stdin, default_page_unit.quantity) == EOF
|
||||||
|
? EX_UNAVAILABLE
|
||||||
|
: EX_OK;
|
||||||
|
} else if (default_page_unit.type == LINES) {
|
||||||
|
return pg_l_u(stdin, default_page_unit.quantity, '\n') == EOF
|
||||||
|
? EX_UNAVAILABLE
|
||||||
|
: EX_OK;
|
||||||
|
} else { return EX_SOFTWARE; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmd_page_down_lines(int argc, char **argv, char **envp) {
|
||||||
|
switch (argc) {
|
||||||
|
case 1: return cmd_default_page(argc, argv, envp);
|
||||||
|
case 2: /* not implemented */
|
||||||
|
default:
|
||||||
|
(void)fprintf(stderr, "Usage: %s" /*" (lines)"*/ "\n", argv[0]);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A CmdMap must be NULL-terminated. */
|
||||||
|
static struct CmdMap{ char *name; int (*fn)(int, char **, char **); }
|
||||||
|
builtins[] = {
|
||||||
|
/* don't make the user feel trapped */
|
||||||
|
{ ":q", cmd_quit }, { ":q!", cmd_quit },
|
||||||
|
{ "exit", cmd_quit }, { "q", cmd_quit }, { "Q", cmd_quit },
|
||||||
|
{ "quit", cmd_quit }, { "ZZ", cmd_quit },
|
||||||
|
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ARGV_MAX 10
|
||||||
|
/* Find and execute the command in the command map, given a corresponding
|
||||||
|
* command line. */
|
||||||
|
static int
|
||||||
|
cmdline_exec(struct CmdMap *map, char *cmdline, char **envp) {
|
||||||
|
static int argc;
|
||||||
|
static char *argv[ARGV_MAX];
|
||||||
|
|
||||||
|
if ((argv[(argc = 0)] = strtok_quoted(cmdline, whitespace)) == NULL) {
|
||||||
|
while (cmdline[0] != '\0') { cmdline = &cmdline[1]; }
|
||||||
|
argv[argc] = cmdline;
|
||||||
|
argv[++argc] = NULL;
|
||||||
|
} else {
|
||||||
|
while (
|
||||||
|
(argv[++argc] = strtok_quoted(NULL, whitespace)) != NULL
|
||||||
|
&& argc < ARGV_MAX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; map->name != NULL; map = &map[1]) {
|
||||||
|
if(strcmp(map->name, argv[0]) == 0) {
|
||||||
|
return map->fn(argc, argv, envp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)fprintf(stderr, "%s: %s: not found\n", program_name, argv[0]);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ioerr(char *argv0) {
|
||||||
|
perror(argv0);
|
||||||
|
|
||||||
|
return EX_IOERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
usage(char *argv0) {
|
||||||
|
(void)fprintf(stderr, "Usage: %s [-p prompt]\n", argv0);
|
||||||
|
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
unsigned char cmd[CMDLINE_MAX];
|
||||||
|
FILE *t;
|
||||||
|
|
||||||
|
if (argc > 0) {
|
||||||
|
int c;
|
||||||
|
|
||||||
|
program_name = argv[0];
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "p:")) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'p': prompt = optarg; break;
|
||||||
|
default: return usage(program_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > optind) { return usage(program_name); }
|
||||||
|
|
||||||
|
|
||||||
|
if ((t = fopen("/dev/tty", "rb")) == NULL) {
|
||||||
|
perror(program_name);
|
||||||
|
|
||||||
|
return EX_OSERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (fputs(prompt, stderr) == EOF) { return ioerr(program_name); }
|
||||||
|
|
||||||
|
// if the line...
|
||||||
|
if (fgets((char *)cmd, (sizeof cmd) / (sizeof *cmd), t) != NULL) {
|
||||||
|
if (strchr((char *)cmd, '\n') == NULL) { // was taken incompletely
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = fgetc(t)) != '\n') { // ...fast-forward stream
|
||||||
|
if (c == EOF) { break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { fputc('\n', stdout); } // EOF at start of line; finish prompt
|
||||||
|
|
||||||
|
if (feof(t)) { return EX_OK; }
|
||||||
|
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
switch ((r = cmdline_exec(builtins, (char *)cmd, NULL))){
|
||||||
|
case EX_OK: case EX_USAGE: break;
|
||||||
|
case EX_UNAVAILABLE: return EX_OK;
|
||||||
|
default: return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UNREACHABLE */ assert(0);
|
||||||
|
}
|
||||||
36
tests/README
36
tests/README
@@ -1,36 +0,0 @@
|
|||||||
The testing suite contains two trees: the Bonsai tree and the POSIX tree:
|
|
||||||
|
|
||||||
.
|
|
||||||
├── README
|
|
||||||
├── bonsai/
|
|
||||||
│ ├── dj.mk
|
|
||||||
│ ├── false.mk
|
|
||||||
│ ├── fop.mk
|
|
||||||
│ └── ...
|
|
||||||
├── posix/
|
|
||||||
└── tests.mk
|
|
||||||
|
|
||||||
The Bonsai tree tests the functionality of Harakit utilities for regressions and
|
|
||||||
other issues relating to compliance to our standards of practice.
|
|
||||||
|
|
||||||
The POSIX tests are currently a work-in-progress. Their status in this
|
|
||||||
repository is uncertain.
|
|
||||||
|
|
||||||
Both sets of tests also inherit the environment set by the top-level Makefile,
|
|
||||||
which sets the BIN variable to the build/bin directory at the root of the
|
|
||||||
project; therefore, each binary is located at $(BIN)/tool for idiomatic access.
|
|
||||||
|
|
||||||
Each test contains a set of PHONY targets which are prefixed with the name of
|
|
||||||
the tool being tested and an underscore. The first target is tests, which
|
|
||||||
depends on all the other targets in the test file. These test files are each
|
|
||||||
included in the top Makefile, so they can be called from the root of the
|
|
||||||
repository. This also means that BIN can be set manually so that tests can be
|
|
||||||
run using make(1) inside of the tests directory:
|
|
||||||
|
|
||||||
$ make -f tests.mk BIN=../build/bin dj_tests
|
|
||||||
|
|
||||||
--
|
|
||||||
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
|
|
||||||
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
|
||||||
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
|
||||||
|
|
||||||
/dev/full:
|
|
||||||
/dev/null:
|
|
||||||
|
|
||||||
.PHONY: dj_tests
|
|
||||||
dj_tests: dj_help dj_full dj_null # dj_skip_stdin
|
|
||||||
|
|
||||||
.PHONY: dj_full
|
|
||||||
# Linux has a /dev/full pseudodevice useful for testing errors.
|
|
||||||
dj_full: $(BIN)/dj /dev/full
|
|
||||||
case "$$(uname)" in \
|
|
||||||
Linux) \
|
|
||||||
$(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \
|
|
||||||
| tee /dev/stderr \
|
|
||||||
| xargs -I out test '1+0 > 0+0; 1024 > 0' = out \
|
|
||||||
;; \
|
|
||||||
esac
|
|
||||||
|
|
||||||
.PHONY: dj_help
|
|
||||||
dj_help: $(BIN)/dj
|
|
||||||
! $(BIN)/dj -h
|
|
||||||
|
|
||||||
.PHONY: dj_null
|
|
||||||
# Read nothing from /dev/null, write nothing to /dev/null.
|
|
||||||
dj_null: $(BIN)/dj /dev/null
|
|
||||||
$(BIN)/dj -Hi /dev/null -o /dev/null 2>&1 \
|
|
||||||
| tee /dev/stderr \
|
|
||||||
| xargs -I out test '0+0 > 0+0; 0 > 0' = out
|
|
||||||
|
|
||||||
# This test currently fails. This is probably due to dj(1) being stale relative
|
|
||||||
# to the main harakit branch. TODO: Reassess once the testing branch is merged.
|
|
||||||
# .PHONY: dj_skip_stdin
|
|
||||||
# # Test skipping stdin.
|
|
||||||
# dj_skip_stdin: $(BIN)/dj
|
|
||||||
# # Pipe 1024B of '\0' into dj(1); skip the first 24B; expect 1000B written.
|
|
||||||
# dd count=1 bs=1024 </dev/zero 2>/dev/null \
|
|
||||||
# | $(BIN)/dj -H -s 24 -o /dev/null 2>&1 \
|
|
||||||
# | tee /dev/stderr \
|
|
||||||
# | xargs -I out test '1+0 > 1+0; 1024 > 1000' = out
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: false_tests
|
|
||||||
false_tests: false_test false_help
|
|
||||||
|
|
||||||
.PHONY: false
|
|
||||||
false_test: $(BIN)/false
|
|
||||||
! $(BIN)/false
|
|
||||||
|
|
||||||
.PHONY: false_help
|
|
||||||
false_help: $(BIN)/false
|
|
||||||
! $(BIN)/false -h
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: fop_tests
|
|
||||||
fop_tests: fop_functionality fop_delimiter fop_help fop_fail
|
|
||||||
|
|
||||||
.PHONY: fop_help
|
|
||||||
fop_help: $(BIN)/fop
|
|
||||||
! $(BIN)/fop -h
|
|
||||||
|
|
||||||
.PHONY: fop_delimiter
|
|
||||||
fop_delimiter: $(BIN)/fop
|
|
||||||
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'
|
|
||||||
|
|
||||||
.PHONY: fop_fail
|
|
||||||
fop_fail: $(BIN)/fop
|
|
||||||
! printf 'test\n' | $(BIN)/fop 1 cat
|
|
||||||
! printf 'test\n' | $(BIN)/fop 'test' cat
|
|
||||||
! printf 'test\n' | $(BIN)/fop -d'test' cat
|
|
||||||
|
|
||||||
.PHONY: fop_functionality
|
|
||||||
fop_functionality: $(BIN)/fop
|
|
||||||
test "$$(printf 'test1\036test1\036test1\n' | $(BIN)/fop 1 sed 's/1/4/g')" \
|
|
||||||
= "$$(printf 'test1\036test4\036test1\n')"
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: hru_tests
|
|
||||||
hru_tests: hru_help hru_functionality hru_negative hru_regressions
|
|
||||||
|
|
||||||
.PHONY: hru_help
|
|
||||||
hru_help: $(BIN)/hru
|
|
||||||
! $(BIN)/hru -h
|
|
||||||
|
|
||||||
.PHONY: hru_functionality
|
|
||||||
hru_functionality: $(BIN)/hru
|
|
||||||
test "$$(printf '1234\n' | $(BIN)/hru)" = '1.2 kB'
|
|
||||||
test "$$(printf '0\n' | $(BIN)/hru)" = '0 B'
|
|
||||||
|
|
||||||
.PHONY: hru_negative
|
|
||||||
hru_negative: $(BIN)/hru
|
|
||||||
! printf '%s\n' '-1' | $(BIN)/hru
|
|
||||||
|
|
||||||
.PHONY: hru_regressions
|
|
||||||
hru_regressions: $(BIN)/hru
|
|
||||||
n=1; \
|
|
||||||
while true; \
|
|
||||||
do \
|
|
||||||
printf '%s\n' "$$n" | $(BIN)/hru || break; \
|
|
||||||
n="$$(($$n * 10))"; \
|
|
||||||
done; \
|
|
||||||
printf 'Max float: %s\n' "$$n"
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: intcmp_tests
|
|
||||||
intcmp_tests: intcmp_help intcmp_e intcmp_g intcmp_l intcmp_combined
|
|
||||||
|
|
||||||
.PHONY: intcmp_help
|
|
||||||
intcmp_help: $(BIN)/intcmp
|
|
||||||
! $(BIN)/intcmp -h
|
|
||||||
|
|
||||||
# These test that integer comparisons are working as they should. For the sake
|
|
||||||
# of readability (to facilitate faster skimming) these recipes follow a
|
|
||||||
# columned format:
|
|
||||||
# $binary -flags d d d d # op
|
|
||||||
# For flag meanings reference intcmp(1) (though they are somewhat self
|
|
||||||
# explanatory). d here refers to a decimal number; a mixture of 1s, 2s, and 3s
|
|
||||||
# (a particularly lovely number) arranged to demonstrate easily the operation
|
|
||||||
# under scrutiny. The commented op is the operation that is true for the given
|
|
||||||
# numbers. For example:
|
|
||||||
# $(BIN)/intcmp -e 3 3 3 3 # ==
|
|
||||||
# op here is ==; 3 == 3 == 3 == 3. The flag being used is -e, to test for
|
|
||||||
# equality, so this test should succeed.
|
|
||||||
# ! $(BIN)/intcmp -l 3 2 1 # >
|
|
||||||
# op here is >; 3 > 2 > 1. The flag being used is -l, to test for each integer
|
|
||||||
# being less than the next, so intcmp should fail - hence the ! at the start of
|
|
||||||
# the invocation. If this test failed, intcmp(1) would be confusing -l for -g,
|
|
||||||
# so that would be a good place to start looking for bugs.
|
|
||||||
|
|
||||||
.PHONY: intcmp_e
|
|
||||||
intcmp_e: $(BIN)/intcmp
|
|
||||||
$(BIN)/intcmp -e 3 3 3 # ==
|
|
||||||
! $(BIN)/intcmp -e 1 2 3 # <
|
|
||||||
! $(BIN)/intcmp -e 3 2 1 # >
|
|
||||||
|
|
||||||
.PHONY: intcmp_g
|
|
||||||
intcmp_g: $(BIN)/intcmp
|
|
||||||
$(BIN)/intcmp -g 3 2 1 # >
|
|
||||||
! $(BIN)/intcmp -g 3 3 3 # ==
|
|
||||||
! $(BIN)/intcmp -g 1 2 3 # <
|
|
||||||
$(BIN)/intcmp -ge 3 3 1 # >=
|
|
||||||
! $(BIN)/intcmp -ge 1 2 3 # <
|
|
||||||
|
|
||||||
.PHONY: intcmp_l
|
|
||||||
intcmp_l: $(BIN)/intcmp
|
|
||||||
$(BIN)/intcmp -l 1 2 3 # <
|
|
||||||
! $(BIN)/intcmp -l 3 3 3 # ==
|
|
||||||
! $(BIN)/intcmp -l 3 2 1 # >
|
|
||||||
$(BIN)/intcmp -le 1 3 3 # <=
|
|
||||||
! $(BIN)/intcmp -le 3 2 1 # >
|
|
||||||
|
|
||||||
.PHONY: intcmp_combined
|
|
||||||
intcmp_combined: $(BIN)/intcmp
|
|
||||||
$(BIN)/intcmp -gl 1 2 3 # <
|
|
||||||
$(BIN)/intcmp -gl 3 2 1 # >
|
|
||||||
$(BIN)/intcmp -gl 1 3 1 # !=
|
|
||||||
! $(BIN)/intcmp -gl 3 3 3 # ==
|
|
||||||
$(BIN)/intcmp -egl 3 1 1 3 # >, ==, <
|
|
||||||
! $(BIN)/intcmp -egl foo # huh?
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
# Copyright (c) 2024 E$(NAME)a Tebibyte <e$(NAME)a@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
NAME = mm
|
|
||||||
TARGET = $(NAME)_tests
|
|
||||||
BINARY = $(BIN)/$(NAME)
|
|
||||||
|
|
||||||
.PHONY: mm_tests
|
|
||||||
mm_tests: mm_args mm_help mm_stderr
|
|
||||||
|
|
||||||
.PHONY: mm_args
|
|
||||||
# mm(1) will error if positional arguments are given without -i or -o
|
|
||||||
mm_args: $(BIN)/mm
|
|
||||||
! $(BIN)/mm argument
|
|
||||||
|
|
||||||
.PHONY: mm_help
|
|
||||||
mm_help: $(BIN)/mm
|
|
||||||
! $(BIN)/mm -h
|
|
||||||
|
|
||||||
.PHONY: mm_stderr
|
|
||||||
# check if stderr is empty upon specifying -e
|
|
||||||
mm_stderr: $(BIN)/mm
|
|
||||||
! test "$$(printf 'test\n' | $(BIN)/mm -e 2>&1 >/dev/null)" = "test"
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
|
||||||
|
|
||||||
.PHONY: npc_tests
|
|
||||||
npc_tests: npc_help npc_args npc_ascii
|
|
||||||
|
|
||||||
.PHONY: npc_help
|
|
||||||
npc_help: $(BIN)/npc
|
|
||||||
! $(BIN)/npc -h
|
|
||||||
|
|
||||||
.PHONY: npc_args
|
|
||||||
# arg parsing
|
|
||||||
npc_args:
|
|
||||||
$(BIN)/npc -e </dev/null
|
|
||||||
$(BIN)/npc -t </dev/null
|
|
||||||
$(BIN)/npc -et </dev/null
|
|
||||||
! $(BIN)/npc -et 5 </dev/null
|
|
||||||
|
|
||||||
.PHONY: npc_ascii
|
|
||||||
# Test 0x00 to 0x7f in input; in other words, the full 7b ASCII range.
|
|
||||||
npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \
|
|
||||||
# npc_ascii_lowers
|
|
||||||
|
|
||||||
.PHONY: npc_ascii_controls
|
|
||||||
# (control characters)
|
|
||||||
npc_ascii_controls:
|
|
||||||
# ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues)
|
|
||||||
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \
|
|
||||||
| $(BIN)/npc \
|
|
||||||
| head -n 1 \
|
|
||||||
| xargs -I out test "^@^A^B^C^D^E^F^G^H" = out
|
|
||||||
|
|
||||||
# ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f
|
|
||||||
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \
|
|
||||||
| $(BIN)/npc \
|
|
||||||
| head -n 2 \
|
|
||||||
| tail -n 1 \
|
|
||||||
| xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_"
|
|
||||||
|
|
||||||
.PHONY: npc_ascii_symbols
|
|
||||||
# ASCII 0x1f to 0x3f (^_ and symbols)
|
|
||||||
npc_ascii_symbols:
|
|
||||||
# shell quoting olympics
|
|
||||||
awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }' \
|
|
||||||
| $(BIN)/npc \
|
|
||||||
| sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \
|
|
||||||
| xargs -I out test "^_ !\"#$$%&'()*+,-./0123456789:;<=>?" = out
|
|
||||||
|
|
||||||
.PHONY: npc_ascii_uppers
|
|
||||||
# ASCII 0x40 to 0x5f (uppercases)
|
|
||||||
npc_ascii_uppers:
|
|
||||||
awk 'BEGIN{ for (i = 64; i < 96; ++i) printf("%c", i); print }' \
|
|
||||||
| $(BIN)/npc \
|
|
||||||
| sed 's/\\/\\\\/' \
|
|
||||||
| xargs -I out test @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ = out
|
|
||||||
|
|
||||||
# This test is broken and will need closer inspection along with the npc(1)
|
|
||||||
# source.
|
|
||||||
# .PHONY: npc_ascii_lowers
|
|
||||||
# # ASCII 0x60 to 0x7f (lowercases)
|
|
||||||
# npc_ascii_lowers:
|
|
||||||
# awk 'BEGIN{ for (i = 96; i < 128; ++i) printf("%c", i); print }' \
|
|
||||||
# | $(BIN)/npc \
|
|
||||||
# | xargs -I out test "\`abcdefghijklmnopqrstuvwxyz{|}~^?" = out
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: rpn_tests
|
|
||||||
rpn_tests: rpn_help rpn_add
|
|
||||||
|
|
||||||
.PHONY: rpn_help
|
|
||||||
rpn_help: $(BIN)/rpn
|
|
||||||
! $(BIN)/rpn -h
|
|
||||||
|
|
||||||
.PHONY: rpn_add
|
|
||||||
rpn_add: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 1 2 +)" -eq 3
|
|
||||||
test "$$($(BIN)/rpn 0.2 0.1 +)" = 0.3
|
|
||||||
|
|
||||||
.PHONY: rpn_sub
|
|
||||||
rpn_sub: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 23 5 -)" -eq 18
|
|
||||||
test "$$($(BIN)/rpn 0.3 0.1)" = 0.2
|
|
||||||
|
|
||||||
.PHONY: rpn_mul
|
|
||||||
rpn_mul: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 1.2 3 '*')" = 3.6
|
|
||||||
test "$$($(BIN)/rpn 0 3 '*')" -eq 0
|
|
||||||
|
|
||||||
.PHONY: rpn_div
|
|
||||||
rpn_div: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 12 5 /)" = 2.4
|
|
||||||
test "$$($(BIN)/rpn 3 0 /)" -eq inf
|
|
||||||
|
|
||||||
.PHONY: rpn_mod
|
|
||||||
rpn_mod: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 12 5 %)" -eq 2
|
|
||||||
test "$$($(BIN)/rpn 9 4 %)" -eq 1
|
|
||||||
|
|
||||||
.PHONY: rpn_flr
|
|
||||||
rpn_flr: $(BIN)/rpn
|
|
||||||
test "$$($(BIN)/rpn 12 5 //)" -eq 2
|
|
||||||
test "$$($(BIN)/rpn 9 4 //)" -eq 2
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
|
||||||
|
|
||||||
.PHONY: scrut_tests
|
|
||||||
scrut_tests: scrut_help scrut_options
|
|
||||||
|
|
||||||
.PHONY: scrut_help
|
|
||||||
scrut_help: $(BIN)/scrut
|
|
||||||
! $(BIN)/scrut -h
|
|
||||||
|
|
||||||
.PHONY: scrut_options
|
|
||||||
# scrut tests file attributes, but files of a certain attribute aren't
|
|
||||||
# guaranteed to be present on a system. This test checks all of the files in
|
|
||||||
# harakit and, if test(1p) says a file matches a certain attribute, then checks
|
|
||||||
# scrut.
|
|
||||||
# opts are space-delimited (for command splitting), sel is not
|
|
||||||
scrut_options: $(BIN)/scrut
|
|
||||||
set -e; \
|
|
||||||
opts="b c d e f g k p r s u w x L S"; \
|
|
||||||
sel=; \
|
|
||||||
find . -name .git -prune -o -print \
|
|
||||||
| while read -r f; do \
|
|
||||||
for opt in $$opts; \
|
|
||||||
do if ! printf "%s\n" $$sel | grep $$opt >/dev/null; then \
|
|
||||||
if test -$$opt "$$f"; then \
|
|
||||||
if ! $(BIN)/scrut -$$opt "$$f"; \
|
|
||||||
then printf "[!!] scrut -%s failed on %s.\n" \
|
|
||||||
$$opt "$$f"; \
|
|
||||||
fi; \
|
|
||||||
sel="$$sel$$opt"; \
|
|
||||||
printf "[OK] Tested scrut -%s using %s\n" \
|
|
||||||
$$opt "$$f"; \
|
|
||||||
fi; \
|
|
||||||
fi; \
|
|
||||||
done; \
|
|
||||||
if printf "%s\n" "$$opts" | sed 's/ //g' | xargs test "$$sel" =; \
|
|
||||||
then break; \
|
|
||||||
fi; \
|
|
||||||
done
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
|
||||||
|
|
||||||
.PHONY: str_tests
|
|
||||||
str_tests: str_help str_isalpha
|
|
||||||
|
|
||||||
.PHONY: str_help
|
|
||||||
str_help: $(BIN)/str
|
|
||||||
! $(BIN)/str -h
|
|
||||||
|
|
||||||
.PHONY: str_isalpha
|
|
||||||
str_isalpha: $(BIN)/str
|
|
||||||
$(BIN)/str isalpha c
|
|
||||||
! $(BIN)/str isalpha 3
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
NAME = strcmp
|
|
||||||
TARGET = $(NAME)_tests
|
|
||||||
BINARY = $(BIN)/$(NAME)
|
|
||||||
|
|
||||||
.PHONY: strcmp_tests
|
|
||||||
strcmp_tests: strcmp_equals strcmp_help strcmp_nocmp strcmp_unequals
|
|
||||||
|
|
||||||
.PHONY: strcmp_equals
|
|
||||||
strcmp_equals: $(BIN)/strcmp
|
|
||||||
$(BIN)/strcmp equals equals
|
|
||||||
$(BIN)/strcmp - -
|
|
||||||
|
|
||||||
.PHONY: strcmp_help
|
|
||||||
strcmp_help: $(BIN)/strcmp
|
|
||||||
! $(BIN)/strcmp -h
|
|
||||||
|
|
||||||
.PHONY: strcmp_nocmp
|
|
||||||
strcmp_nocmp: $(BIN)/strcmp
|
|
||||||
! $(BIN)/strcmp nocmp
|
|
||||||
|
|
||||||
.PHONY: strcmp_unequals
|
|
||||||
strcmp_unequals: $(BIN)/strcmp
|
|
||||||
! $(BIN)/strcmp unequals equals
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
|
||||||
|
|
||||||
.PHONY: swab_tests
|
|
||||||
swab_tests: swab_help swab_examples
|
|
||||||
|
|
||||||
.PHONY: swab_help
|
|
||||||
swab_help: $(BIN)/swab
|
|
||||||
! $(BIN)/swab -h
|
|
||||||
|
|
||||||
.PHONY: swab_examples
|
|
||||||
# These are the examples present in the man page.
|
|
||||||
swab_examples: $(BIN)/swab
|
|
||||||
printf 'hello world!\n' \
|
|
||||||
| $(BIN)/swab \
|
|
||||||
| xargs -I out test 'ehll oowlr!d' = out
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
.PHONY: true_tests
|
|
||||||
true_tests: true_test
|
|
||||||
|
|
||||||
.PHONY: true_help
|
|
||||||
true_help: $(BIN)/true
|
|
||||||
$(BIN)/true -h
|
|
||||||
|
|
||||||
.PHONY: true_test
|
|
||||||
true_test: $(BIN)/true
|
|
||||||
$(BIN)/true
|
|
||||||
24
tests/posix-compat.sh
Executable file
24
tests/posix-compat.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
# SPDX-License-Identifier: FSFAP
|
||||||
|
#
|
||||||
|
# Copying and distribution of this file, with or without modification, are
|
||||||
|
# permitted in any medium without royalty provided the copyright notice and this
|
||||||
|
# notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if ! ls Makefile >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
printf '%s: Run this script in the root of the project.\n' "$0" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Starting POSIX compatibility testing.\n"
|
||||||
|
|
||||||
|
for utility in tests/posix/*; do
|
||||||
|
printf '%s: %s: Testing utility.\n' "$0" "$utility"
|
||||||
|
"$utility"
|
||||||
|
printf '\n'
|
||||||
|
done
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
# Strictly POSIX-compliant cat(1) implementation. See cat(1p)
|
|
||||||
|
|
||||||
for arg in "$@"; do
|
|
||||||
case "$arg" in
|
|
||||||
-u) args="$(printf '%s %s\n' "$args" "$arg")" ;;
|
|
||||||
*) args="$(printf -- '%s -i %s\n' "$args" "$arg")" ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# See IEEE Std 1003.1-2017 3.282
|
|
||||||
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282
|
|
||||||
IFS=' '
|
|
||||||
|
|
||||||
mm $args
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
# Strictly POSIX-compliant false(1) implementation. See false(1p)
|
|
||||||
|
|
||||||
false "$@"
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
# Strictly POSIX-compliant true(1) implementation. See true(1p)
|
|
||||||
true "$@"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
PATH="$PWD/bin:$PATH"
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
# SPDX-License-Identifier: FSFAP
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
|
||||||
|
|
||||||
|
|
||||||
#TESTFILES != for file in tests/bonsai/*.mk tests/posix/*.mk; do printf '%s ' "$$file"; done;
|
|
||||||
TESTFILES != for file in tests/bonsai/*.mk; do printf '%s ' "$$file"; done;
|
|
||||||
|
|
||||||
TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \
|
|
||||||
| sed 's/\.mk/_tests/g'
|
|
||||||
|
|
||||||
include $(TESTFILES)
|
|
||||||
Reference in New Issue
Block a user