3
0

dc.tests 2.0 KB

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