test-ob-C.el 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. ;;; test-ob-C.el --- tests for ob-C.el
  2. ;; Copyright (c) 2010-2014 Sergey Litvinov, Thierry Banel
  3. ;; Authors: Sergey Litvinov, Thierry Banel
  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-C)
  17. (signal 'missing-test-dependency "Support for C code blocks"))
  18. (ert-deftest ob-C/assert ()
  19. (should t))
  20. (ert-deftest ob-C/simple-program ()
  21. "Hello world program."
  22. (if (executable-find org-babel-C++-compiler)
  23. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  24. (org-babel-next-src-block 1)
  25. (should (= 42 (org-babel-execute-src-block))))))
  26. (ert-deftest ob-D/simple-program ()
  27. "Hello world program."
  28. (if (executable-find org-babel-D-compiler)
  29. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  30. (org-babel-next-src-block 2)
  31. (should (= 42 (org-babel-execute-src-block))))))
  32. (ert-deftest ob-C/integer-var ()
  33. "Test of an integer variable."
  34. (if (executable-find org-babel-C++-compiler)
  35. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  36. (org-babel-next-src-block 3)
  37. (should (= 12 (org-babel-execute-src-block))))))
  38. (ert-deftest ob-D/integer-var ()
  39. "Test of an integer variable."
  40. (if (executable-find org-babel-D-compiler)
  41. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  42. (org-babel-next-src-block 4)
  43. (should (= 12 (org-babel-execute-src-block))))))
  44. (ert-deftest ob-C/two-integer-var ()
  45. "Test of two input variables"
  46. (if (executable-find org-babel-C++-compiler)
  47. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  48. (org-babel-next-src-block 5)
  49. (should (= 22 (org-babel-execute-src-block))))))
  50. (ert-deftest ob-D/two-integer-var ()
  51. "Test of two input variables"
  52. (if (executable-find org-babel-D-compiler)
  53. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  54. (org-babel-next-src-block 6)
  55. (should (= 22 (org-babel-execute-src-block))))))
  56. (ert-deftest ob-C/string-var ()
  57. "Test of a string input variable"
  58. (if (executable-find org-babel-C++-compiler)
  59. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  60. (org-babel-next-src-block 7)
  61. (should (equal "word 4" (org-babel-execute-src-block))))))
  62. (ert-deftest ob-D/string-var ()
  63. "Test of a string input variable"
  64. (if (executable-find org-babel-D-compiler)
  65. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  66. (org-babel-next-src-block 8)
  67. (should (equal "word 4" (org-babel-execute-src-block))))))
  68. (ert-deftest ob-C/preprocessor ()
  69. "Test of a string variable"
  70. (if (executable-find org-babel-C++-compiler)
  71. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  72. (org-babel-next-src-block 9)
  73. (should (= 42 (org-babel-execute-src-block))))))
  74. (ert-deftest ob-C/table ()
  75. "Test of a table output"
  76. (if (executable-find org-babel-C++-compiler)
  77. (org-test-at-id "2df1ab83-3fa3-462a-a1f3-3aef6044a874"
  78. (org-babel-next-src-block 1)
  79. (should (equal '((1) (2)) (org-babel-execute-src-block))))))
  80. (ert-deftest ob-D/table ()
  81. "Test of a table output"
  82. (if (executable-find org-babel-D-compiler)
  83. (org-test-at-id "2df1ab83-3fa3-462a-a1f3-3aef6044a874"
  84. (org-babel-next-src-block 2)
  85. (should (equal '((1) (2)) (org-babel-execute-src-block))))))
  86. (ert-deftest ob-C/list-var ()
  87. "Test of a list input variable"
  88. (if (executable-find org-babel-C++-compiler)
  89. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  90. (org-babel-next-src-block 1)
  91. (should (string= "abcdef2" (org-babel-execute-src-block))))))
  92. (ert-deftest ob-D/list-var ()
  93. "Test of a list input variable"
  94. (if (executable-find org-babel-D-compiler)
  95. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  96. (org-babel-next-src-block 2)
  97. (should (string= "abcdef2" (org-babel-execute-src-block))))))
  98. (ert-deftest ob-C/vector-var ()
  99. "Test of a vector input variable"
  100. (if (executable-find org-babel-C++-compiler)
  101. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  102. (org-babel-next-src-block 3)
  103. (should (equal 122 (org-babel-execute-src-block))))))
  104. (ert-deftest ob-D/vector-var ()
  105. "Test of a vector input variable"
  106. (if (executable-find org-babel-D-compiler)
  107. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  108. (org-babel-next-src-block 4)
  109. (should (equal 122 (org-babel-execute-src-block))))))
  110. (ert-deftest ob-C/list-list-var ()
  111. "Test of a list list input variable"
  112. (if (executable-find org-babel-C++-compiler)
  113. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  114. (org-babel-next-src-block 5)
  115. (should (equal '((1 3) (2 4)) (org-babel-execute-src-block))))))
  116. (ert-deftest ob-D/list-list-var ()
  117. "Test of a list list input variable"
  118. (if (executable-find org-babel-D-compiler)
  119. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  120. (org-babel-next-src-block 6)
  121. (should (equal '((1 3) (2 4)) (org-babel-execute-src-block))))))
  122. (ert-deftest ob-C/inhomogeneous_table ()
  123. "Test inhomogeneous input table"
  124. (if (executable-find org-babel-C++-compiler)
  125. (org-test-at-id "e112bc2e-419a-4890-99c2-7ac4779531cc"
  126. (org-babel-next-src-block 1)
  127. (should (equal
  128. '(("monday" 34)
  129. ("tuesday" 41)
  130. ("wednesday" 56)
  131. ("thursday" 17)
  132. ("friday" 12)
  133. ("saturday" 7)
  134. ("sunday" 4)
  135. ("Friday" "friday"))
  136. (org-babel-execute-src-block))))))
  137. (ert-deftest ob-D/inhomogeneous_table ()
  138. "Test inhomogeneous input table"
  139. (if (executable-find org-babel-D-compiler)
  140. (org-test-at-id "e112bc2e-419a-4890-99c2-7ac4779531cc"
  141. (org-babel-next-src-block 2)
  142. (should (equal
  143. '(("monday" 34)
  144. ("tuesday" 41)
  145. ("wednesday" 56)
  146. ("thursday" 17)
  147. ("friday" 12)
  148. ("saturday" 7)
  149. ("sunday" 4)
  150. ("Friday" "friday"))
  151. (org-babel-execute-src-block))))))
  152. ;;; test-ob-C.el ends here