test_json_script.t 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. set test bin path:
  2. $ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH"
  3. $ export TEST_INPUTS="$TESTDIR/inputs"
  4. $ alias js="valgrind --quiet --leak-check=full test-json-script"
  5. $ alias js-san="test-json-script-san"
  6. check that json-script is producing expected results:
  7. $ js
  8. Usage: test-json-script [VARNAME=value] <filename_json_script>
  9. [254]
  10. $ js-san
  11. Usage: test-json-script-san [VARNAME=value] <filename_json_script>
  12. [254]
  13. $ echo '}' > test.json; js test.json
  14. load JSON data from test.json failed.
  15. $ echo '}' > test.json; js-san test.json
  16. load JSON data from test.json failed.
  17. $ js nada.json 2>&1 | grep load.*failed
  18. load JSON data from nada.json failed.
  19. $ js-san nada.json 2>&1 | grep load.*failed
  20. load JSON data from nada.json failed.
  21. $ echo '[ [ ] [ ] ]' > test.json; js test.json
  22. load JSON data from test.json failed.
  23. $ echo '[ [ ] [ ] ]' > test.json; js-san test.json
  24. load JSON data from test.json failed.
  25. check example json-script:
  26. $ js $TEST_INPUTS/json-script.json
  27. exec /%/
  28. exec_if_or
  29. $ js-san $TEST_INPUTS/json-script.json
  30. exec /%/
  31. exec_if_or
  32. $ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
  33. exec meh /%/
  34. exec_if_or meep
  35. $ js-san EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
  36. exec meh /%/
  37. exec_if_or meep
  38. check has expression:
  39. $ echo '
  40. > [
  41. > [ "if",
  42. > [ "has", "VAR" ],
  43. > [ "echo", "bar" ],
  44. > [ "echo", "baz" ]
  45. > ]
  46. > ]' > test.json
  47. $ js VAR=foo test.json
  48. echo bar
  49. $ js-san VAR=foo test.json
  50. echo bar
  51. $ js VAR=bar test.json
  52. echo bar
  53. $ js-san VAR=bar test.json
  54. echo bar
  55. $ js test.json
  56. echo baz
  57. $ js-san test.json
  58. echo baz
  59. check eq expression:
  60. $ echo '
  61. > [
  62. > [ "if",
  63. > [ "eq", "VAR", "bar" ],
  64. > [ "echo", "foo" ],
  65. > [ "echo", "baz" ]
  66. > ]
  67. > ]' > test.json
  68. $ js VAR=bar test.json
  69. echo foo
  70. $ js-san VAR=bar test.json
  71. echo foo
  72. $ js VAR=xxx test.json
  73. echo baz
  74. $ js-san VAR=xxx test.json
  75. echo baz
  76. $ js test.json
  77. echo baz
  78. $ js-san test.json
  79. echo baz
  80. check regex single expression:
  81. $ echo '
  82. > [
  83. > [ "if",
  84. > [ "regex", "VAR", ".ell." ],
  85. > [ "echo", "bar" ],
  86. > [ "echo", "baz" ]
  87. > ]
  88. > ]' > test.json
  89. $ js VAR=hello test.json
  90. echo bar
  91. $ js-san VAR=hello test.json
  92. echo bar
  93. $ js VAR=.ell. test.json
  94. echo bar
  95. $ js-san VAR=.ell. test.json
  96. echo bar
  97. $ js test.json
  98. echo baz
  99. $ js-san test.json
  100. echo baz
  101. $ js VAR= test.json
  102. echo baz
  103. $ js-san VAR= test.json
  104. echo baz
  105. $ js VAR=hell test.json
  106. echo baz
  107. $ js-san VAR=hell test.json
  108. echo baz