logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 7c36b3ccf8480f9c0244f5f4658a9b9b95638286
parent 7ac6c2585ee0c6cf66ceda27f7572a434e29c1b7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  2 Sep 2024 14:07:53 +0200

test-cmd/expr.sh: new

Diffstat:

Mtest-cmd/Kyuafile3++-
Atest-cmd/expr.sh58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -22,6 +22,7 @@ tap_test_program{name="date.sh", required_files=basedir.."/cmd/date", timeout=1} tap_test_program{name="dirname.sh", required_files=basedir.."/cmd/dirname", timeout=1} tap_test_program{name="echo.sh", required_files=basedir.."/cmd/echo", timeout=1} tap_test_program{name="env.sh", required_files=basedir.."/cmd/env", timeout=1} +tap_test_program{name="expr.sh", required_files=basedir.."/cmd/expr", timeout=1} tap_test_program{name="false.sh", required_files=basedir.."/cmd/false", timeout=1} tap_test_program{name="head.sh", required_files=basedir.."/cmd/head", timeout=1} tap_test_program{name="id.sh", required_files=basedir.."/cmd/id", timeout=1} @@ -38,6 +39,6 @@ tap_test_program{name="strings.sh", required_files=basedir.."/cmd/strings", time tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2} tap_test_program{name="true.sh", required_files=basedir.."/cmd/true", timeout=1} tap_test_program{name="tty.sh", required_files=basedir.."/cmd/tty", timeout=1} -tap_test_program{name="wc.sh", required_files=basedir.."/cmd/wc", timeout=1} tap_test_program{name="uname.sh", required_files=basedir.."/cmd/uname", timeout=1} tap_test_program{name="unlink.sh", required_files=basedir.."/cmd/unlink", timeout=1} +tap_test_program{name="wc.sh", required_files=basedir.."/cmd/wc", timeout=1} diff --git a/test-cmd/expr.sh b/test-cmd/expr.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +WD="$(dirname "$0")/../" +target="${WD}/cmd/expr" +plans=23 + +. "${WD}/test-cmd/tap.sh" + +t int 1 '1 +' + +t_args group '4 +' '(' 2 '*' 3 ')' - 2 + +t_args 'char_count:1234' '4 +' "X1234" : '.*' - 1 +t_args 'char_count:12345' '5 +' "X12345" : '.*' - 1 + +t_args mul '6 +' 3 '*' 2 +t_args div '3 +' 7 / 2 +t_args rem '1 +' 7 % 2 +t_args add '3 +' 1 + 2 +t_args sub '2 +' 3 - 1 + +good='1 +' +bad='0 +' + +t_args eq:eq "$good" 1 = 1 +t_args --exit=1 eq:ne "$bad" 1 = 0 + +t_args gt:gt "$good" 2 '>' 1 +t_args --exit=1 gt:lt "$bad" 1 '>' 2 + +t_args gte:gt "$good" 2 '>=' 1 +t_args gte:eq "$good" 2 '>=' 2 +t_args --exit=1 gte:lt "$bad" 1 '>=' 2 + +t_args lt:lt "$good" 1 '<' 2 +t_args --exit=1 lt:gt "$bad" 2 '<' 1 + +t_args lte:lt "$good" 1 '<=' 2 +t_args lte:eq "$good" 2 '<=' 2 +t_args --exit=1 lte:gt "$bad" 2 '<=' 1 + +t_args ne:ne "$good" 1 != 2 +t_args --exit=1 ne:eq "$bad" 1 != 1 + +# TODO: and (&), or (|)