test-ob-vala.el 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ;;; test-ob-vala.el --- tests for ob-vala.el
  2. ;; Copyright (C) 2017 Christian Garbs
  3. ;; Authors: Christian Garbs
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (unless (featurep 'ob-vala)
  17. (signal 'missing-test-dependency "Support for Vala code blocks"))
  18. (org-test-for-executable org-babel-vala-compiler)
  19. (ert-deftest ob-vala/assert ()
  20. (should t))
  21. (ert-deftest ob-vala/static-output ()
  22. "Parse static output to variable."
  23. (should (= 42
  24. (org-test-with-temp-text
  25. "
  26. #+begin_src vala
  27. class Demo.HelloWorld : GLib.Object {
  28. public static int main(string[] args) {
  29. stdout.printf(\"42\n\");
  30. return 0;
  31. }
  32. }
  33. #+end_src"
  34. (org-babel-next-src-block)
  35. (org-babel-execute-src-block)))))
  36. (ert-deftest ob-vala/return-numerics ()
  37. "Return multiple numeric values."
  38. (should (equal '((0) (1) (2))
  39. (org-test-with-temp-text
  40. "
  41. #+begin_src vala
  42. class Demo.HelloWorld : GLib.Object {
  43. public static int main(string[] args) {
  44. for (int i=0; i<3; i++) {
  45. stdout.printf(\"%d\n\", i);
  46. }
  47. return 0;
  48. }
  49. }
  50. #+end_src"
  51. (org-babel-next-src-block)
  52. (org-babel-execute-src-block)))))
  53. (ert-deftest ob-vala/compiler-args ()
  54. "Pass compiler arguments."
  55. (should (string= "Foo"
  56. (org-test-with-temp-text
  57. "
  58. #+begin_src vala :flags -D FOO
  59. class Demo.HelloWorld : GLib.Object {
  60. public static int main(string[] args) {
  61. #if FOO
  62. stdout.printf(\"Foo\n\");
  63. #else
  64. stdout.printf(\"No foo\n\");
  65. #endif
  66. return 0;
  67. }
  68. }
  69. #+end_src"
  70. (org-babel-next-src-block)
  71. (org-babel-execute-src-block)))))
  72. (ert-deftest ob-vala/comdline-args ()
  73. "Pass commandline arguments."
  74. (should (equal '(("foo") ("bar"))
  75. (org-test-with-temp-text
  76. "
  77. #+begin_src vala :cmdline foo bar
  78. class Demo.HelloWorld : GLib.Object {
  79. public static int main(string[] args) {
  80. // skip args[0], it is the binary name
  81. for (int i=1; i < args.length; i++) {
  82. stdout.printf(\"%s\n\" , args[i]);
  83. }
  84. return 0;
  85. }
  86. }
  87. #+end_src"
  88. (org-babel-next-src-block)
  89. (org-babel-execute-src-block)))))
  90. ;;; test-ob-vala.el ends here