busybox/testsuite/dc.tests
<<
>>
Prefs
   1#!/bin/sh
   2# Copyright 2015 by Bernhard Reutner-Fischer
   3# Licensed under GPLv2 or later, see file LICENSE in this source tree.
   4
   5. ./testing.sh
   6
   7# testing "test name" "command" "expected result" "file input" "stdin"
   8
   9testing "dc basic syntax (stdin, multiple args)" \
  10        "dc" \
  11        "30\n" \
  12        "" "10 20+p"
  13
  14testing "dc basic syntax (argv, single arg)" \
  15        "dc -e'10 20+p'" \
  16        "30\n" \
  17        "" ""
  18
  19testing "dc basic syntax (argv, multiple args)" \
  20        "dc -e10 -e20+p" \
  21        "30\n" \
  22        "" ""
  23
  24testing "dc complex with spaces (single arg)" \
  25        "dc -e'8 8 * 2 2 + / p'" \
  26        "16\n" \
  27        "" ""
  28
  29testing "dc complex without spaces (single arg)" \
  30        "dc -e'8 8*2 2+/p'" \
  31        "16\n" \
  32        "" ""
  33
  34testing "dc complex with spaces (multiple args)" \
  35        "dc -e8 -e8 -e\* -e2 -e2 -e+ -e/ -ep" \
  36        "16\n" \
  37        "" ""
  38
  39testing "dc complex without spaces (multiple args)" \
  40        "dc -e8 -e8\*2 -e2+/p" \
  41        "16\n" \
  42        "" ""
  43
  44optional FEATURE_DC_BIG
  45# All tests below depend on FEATURE_DC_BIG
  46
  47testing "dc read" \
  48        "dc -finput" \
  49        "2\n9\n1\n" \
  50        "1?2\nf" "9\n"
  51
  52testing "dc read string" \
  53        "dc -finput" \
  54        "2\nstr\n1\n" \
  55        "1?2\nf" "[str]\n"
  56
  57testing "dc '>a' (conditional execute string) 1" \
  58        "dc" \
  59        "1\n9\n" \
  60        "" "[1p]sa [2p]sb 1 2>a\n9p"
  61
  62testing "dc '>a' (conditional execute string) 2" \
  63        "dc" \
  64        "9\n" \
  65        "" "[1p]sa [2p]sb 2 1>a\n9p"
  66
  67testing "dc '>aeb' (conditional execute string with else)" \
  68        "dc" \
  69        "2\n9\n" \
  70        "" "[1p]sa [2p]sb 2 1>aeb\n9p"
  71
  72testing "dc space can be a register" \
  73        "dc" \
  74        "2\n9\n" \
  75        "" "[2p]s \n[3p]\nl x\n9p"
  76
  77testing "dc newline can be a register" \
  78        "dc" \
  79        "2\n9\n" \
  80        "" "[2p]s\n[3p]l\nx\n9p"
  81
  82for f in dc_*.dc; do
  83        r="`basename "$f" .dc`_results.txt"
  84        test -f "$r" || continue
  85        # testing "test name" "command" "expected result" "file input" "stdin"
  86        testing "dc $f" \
  87                "{ { dc $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
  88                "E:0\nE:0\n" \
  89                "" ""
  90done
  91
  92for f in dcx_*.dc; do
  93        r="`basename "$f" .dc`_results.txt"
  94        test -f "$r" || continue
  95        # testing "test name" "command" "expected result" "file input" "stdin"
  96        testing "dc -x $f" \
  97                "{ { dc -x $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
  98                "E:0\nE:0\n" \
  99                "" ""
 100done
 101
 102exit $FAILCOUNT
 103