test-ob-C.el 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. ;;; test-ob-C.el --- tests for ob-C.el -*- lexical-binding: t; -*-
  2. ;; Copyright (c) 2010-2014, 2019 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 <https://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-C/symbol-include ()
  27. "Hello world program with unquoted :includes."
  28. (if (executable-find org-babel-C++-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-D/simple-program ()
  33. "Hello world program."
  34. (if (executable-find org-babel-D-compiler)
  35. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  36. (org-babel-next-src-block 3)
  37. (should (= 42 (org-babel-execute-src-block))))))
  38. (ert-deftest ob-C/integer-var ()
  39. "Test of an integer variable."
  40. (if (executable-find org-babel-C++-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-D/integer-var ()
  45. "Test of an integer variable."
  46. (if (executable-find org-babel-D-compiler)
  47. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  48. (org-babel-next-src-block 5)
  49. (should (= 12 (org-babel-execute-src-block))))))
  50. (ert-deftest ob-C/two-integer-var ()
  51. "Test of two input variables"
  52. (if (executable-find org-babel-C++-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-D/two-integer-var ()
  57. "Test of two input variables"
  58. (if (executable-find org-babel-D-compiler)
  59. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  60. (org-babel-next-src-block 7)
  61. (should (= 22 (org-babel-execute-src-block))))))
  62. (ert-deftest ob-C/string-var ()
  63. "Test of a string input variable"
  64. (if (executable-find org-babel-C++-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-D/string-var ()
  69. "Test of a string input variable"
  70. (if (executable-find org-babel-D-compiler)
  71. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  72. (org-babel-next-src-block 9)
  73. (should (equal "word 4" (org-babel-execute-src-block))))))
  74. (ert-deftest ob-C/preprocessor ()
  75. "Test of a string variable"
  76. (if (executable-find org-babel-C++-compiler)
  77. (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
  78. (org-babel-next-src-block 10)
  79. (should (= 42 (org-babel-execute-src-block))))))
  80. (ert-deftest ob-C/table ()
  81. "Test of a table output"
  82. (if (executable-find org-babel-C++-compiler)
  83. (org-test-at-id "2df1ab83-3fa3-462a-a1f3-3aef6044a874"
  84. (org-babel-next-src-block 1)
  85. (should (equal '((1) (2)) (org-babel-execute-src-block))))))
  86. (ert-deftest ob-D/table ()
  87. "Test of a table output"
  88. (if (executable-find org-babel-D-compiler)
  89. (org-test-at-id "2df1ab83-3fa3-462a-a1f3-3aef6044a874"
  90. (org-babel-next-src-block 2)
  91. (should (equal '((1) (2)) (org-babel-execute-src-block))))))
  92. (ert-deftest ob-C/list-var ()
  93. "Test of a list input variable"
  94. (if (executable-find org-babel-C++-compiler)
  95. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  96. (org-babel-next-src-block 1)
  97. (should (string= "abcdef2" (org-babel-execute-src-block))))))
  98. (ert-deftest ob-D/list-var ()
  99. "Test of a list input variable"
  100. (if (executable-find org-babel-D-compiler)
  101. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  102. (org-babel-next-src-block 2)
  103. (should (string= "abcdef2" (org-babel-execute-src-block))))))
  104. (ert-deftest ob-C/vector-var ()
  105. "Test of a vector input variable"
  106. (if (executable-find org-babel-C++-compiler)
  107. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  108. (org-babel-next-src-block 3)
  109. (should (equal 122 (org-babel-execute-src-block))))))
  110. (ert-deftest ob-D/vector-var ()
  111. "Test of a vector input variable"
  112. (if (executable-find org-babel-D-compiler)
  113. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  114. (org-babel-next-src-block 4)
  115. (should (equal 122 (org-babel-execute-src-block))))))
  116. (ert-deftest ob-C/list-list-var ()
  117. "Test of a list list input variable"
  118. (if (executable-find org-babel-C++-compiler)
  119. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  120. (org-babel-next-src-block 5)
  121. (should (equal '((1 3) (2 4)) (org-babel-execute-src-block))))))
  122. (ert-deftest ob-D/list-list-var ()
  123. "Test of a list list input variable"
  124. (if (executable-find org-babel-D-compiler)
  125. (org-test-at-id "cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5"
  126. (org-babel-next-src-block 6)
  127. (should (equal '((1 3) (2 4)) (org-babel-execute-src-block))))))
  128. (ert-deftest ob-C/inhomogeneous_table ()
  129. "Test inhomogeneous input table"
  130. (if (executable-find org-babel-C++-compiler)
  131. (org-test-at-id "e112bc2e-419a-4890-99c2-7ac4779531cc"
  132. (org-babel-next-src-block 1)
  133. (should (equal
  134. '(("monday" 34)
  135. ("tuesday" 41)
  136. ("wednesday" 56)
  137. ("thursday" 17)
  138. ("friday" 12)
  139. ("saturday" 7)
  140. ("sunday" 4)
  141. ("Friday" "friday"))
  142. (org-babel-execute-src-block))))))
  143. (ert-deftest ob-D/inhomogeneous_table ()
  144. "Test inhomogeneous input table"
  145. (if (executable-find org-babel-D-compiler)
  146. (org-test-at-id "e112bc2e-419a-4890-99c2-7ac4779531cc"
  147. (org-babel-next-src-block 2)
  148. (should (equal
  149. '(("monday" 34)
  150. ("tuesday" 41)
  151. ("wednesday" 56)
  152. ("thursday" 17)
  153. ("friday" 12)
  154. ("saturday" 7)
  155. ("sunday" 4)
  156. ("Friday" "friday"))
  157. (org-babel-execute-src-block))))))
  158. (ert-deftest ob-C/ouput-doublequotes ()
  159. "Double quotes not swallowed in raw output"
  160. (if (executable-find org-babel-C++-compiler)
  161. (org-test-at-id "9386490b-4063-4400-842c-4a634edbedf5"
  162. (org-babel-next-src-block 1)
  163. (should (equal
  164. "\"line 1\"\n\"line 2\"\n\"line 3\"\n"
  165. (org-babel-execute-src-block))))))
  166. (provide 'test-ob-C)
  167. ;;; test-ob-C.el ends here