diff options
| author | EuAndreh <eu@euandre.org> | 2026-04-21 22:16:06 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-04-21 22:16:06 -0300 |
| commit | f478620978ae884aa5e7a0ddb742faa5cb23ae3a (patch) | |
| tree | 0e2c87b1e3d5d99aaccd99d24d47ca45d6d2c1fe /tests | |
| parent | Remove Go code (diff) | |
| download | papod-f478620978ae884aa5e7a0ddb742faa5cb23ae3a.tar.gz papod-f478620978ae884aa5e7a0ddb742faa5cb23ae3a.tar.xz | |
m
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/cli-opts.sh | 4 | ||||
| -rw-r--r-- | tests/fuzz/api.clj | 11 | ||||
| -rw-r--r-- | tests/integration.clj | 6 | ||||
| -rw-r--r-- | tests/lib.sh | 122 | ||||
| -rw-r--r-- | tests/unit.clj | 54 |
5 files changed, 193 insertions, 4 deletions
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh deleted file mode 100755 index fcb62ca..0000000 --- a/tests/cli-opts.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eu - -exit diff --git a/tests/fuzz/api.clj b/tests/fuzz/api.clj new file mode 100644 index 0000000..d389c13 --- /dev/null +++ b/tests/fuzz/api.clj @@ -0,0 +1,11 @@ +(ns fuzz.api + (:require [base]) + (:gen-class)) + + + +(defn -main + [& args] + (base/run-fuzz-loop (System/currentTimeMillis) + (base/duration-ms-from-args args) + (fn [_i] (base/uuidv7)))) diff --git a/tests/integration.clj b/tests/integration.clj new file mode 100644 index 0000000..18811a2 --- /dev/null +++ b/tests/integration.clj @@ -0,0 +1,6 @@ +(ns integration + (:gen-class)) + + +(defn -main + [& _args]) diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 0000000..649c61d --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,122 @@ +#!/bin/sh + + +export TMPDIR="${TMPDIR:-$XDG_RUNTIME_DIR}" + +end="\033[0m" +red="\033[0;31m" +green="\033[0;32m" +yellow="\033[0;33m" + +N= +OUT= +ERR= +STATUS= + +ERROR() { + # shellcheck disable=2059 + printf "${red}ERROR${end}" +} + +print_debug_info() { + # shellcheck disable=2016 + printf 'LINENO: %s\n$OUT: %s\n$ERR: %s\n' \ + "$N" "$OUT" "$ERR" >&2 +} + +assert_status() { + if [ "$STATUS" != "$1" ]; then + printf '\n%s: Bad status.\n\nexpected: %s\ngot: %s\n' \ + "$(ERROR)" "$1" "$STATUS" >&2 + print_debug_info + exit 1 + fi +} + +assert_usage() { + if ! grep -Fq 'Usage' "$1"; then + echo 'Expected to find "Usage" text, it was missing:' >&2 + cat "$1" >&2 + print_debug_info + exit 1 + fi +} + +assert_empty_stream() { + if [ -s "$2" ]; then + FMT='\n%s: Expected %s (%s) to be empty, but has content:\n%s\n' + # shellcheck disable=2059 + printf "$FMT" \ + "$(ERROR)" "$1" "$2" "$(cat "$2")" >&2 + print_debug_info + exit 1 + fi +} + +assert_empty_stdout() { + assert_empty_stream STDOUT "$OUT" +} + +assert_empty_stderr() { + assert_empty_stream STDERR "$ERR" +} + +assert_stream() { + if [ "$(cat "$2")" != "$3" ]; then + printf '\n%s: Bad %s (%s)\n\nexpected: %s\ngot: %s\n' \ + "$(ERROR)" "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info + exit 1 + fi +} + +assert_stdout() { + assert_stream STDOUT "$OUT" "$1" +} + +assert_stderr() { + assert_stream STDERR "$ERR" "$1" +} + +assert_grep_stream() { + if ! grep -qE "$3" "$2"; then + printf '\n%s: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \ + "$(ERROR)" "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info + exit 1 + fi +} + +assert_grep_stdout() { + assert_grep_stream STDOUT "$OUT" "$1" +} + +assert_grep_stderr() { + assert_grep_stream STDERR "$ERR" "$1" +} + +assert_fgrep_stream() { + if ! grep -Fq -- "$3" "$2"; then + printf '\n%s: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \ + "$(ERROR)" "$1" "$2" "$3" "$(cat "$2")" >&2 + print_debug_info + exit 1 + fi +} + +assert_fgrep_stdout() { + assert_fgrep_stream STDOUT "$OUT" "$1" +} + +assert_fgrep_stderr() { + assert_fgrep_stream STDERR "$ERR" "$1" +} + +testing() { + printf "${yellow}testing${end}: %s..." "$1" >&2 +} + +test_ok() { + # shellcheck disable=2059 + printf " ${green}OK${end}.\n" >&2 +} diff --git a/tests/unit.clj b/tests/unit.clj new file mode 100644 index 0000000..e92b389 --- /dev/null +++ b/tests/unit.clj @@ -0,0 +1,54 @@ +(ns unit + (:require [clojure.test :as t :refer [are deftest is testing]] + [papod]) + (:gen-class)) + + + +(def parse @#'papod/get-raw-message) +(deftest test_get-raw-message + (testing ":needs-more states" + (is (= (parse "") + {:input "" + :status :needs-more})) + (is (= (parse "some text") + {:input "some text" + :status :needs-more})) + (is (= (parse "newline\nonly") + {:input "newline\nonly" + :status :needs-more})) + (is (= (parse "CR\rLF\n\r") + {:input "CR\rLF\n\r" + :status :needs-more}))) + (testing "empty messages" + (is (= (parse " \r\nblah\r\n") + {:status :accepting + :input "blah\r\n" + :raw-message false}))) + (testing "input splitting" + (is (= (parse "BEFORE\r\nAFTER\r\nTAIL") + {:status :accepting + :input "AFTER\r\nTAIL" + :raw-message "BEFORE"})))) + +(def parse-message @#'papod/parse-message) +(deftest test_parse-message + (testing "only commands" + (is (= (parse-message "CMD") + [{:prefix nil + :command "CMD" + :params []} + nil])))) + +; (parse-message " CMD") + + +(defn -main + [& _args] + (binding [*out* *err*] + (let [{:keys [fail error] :as res} (t/run-tests 'unit) + status (if (zero? (+ fail error)) + 0 + 1)] + (prn res) + (System/exit status)))) |
