emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BABEL,PATCH] ob-fortran, ert tests
@ 2011-07-20 22:54 Litvinov Sergey
  2011-07-21  9:23 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Litvinov Sergey @ 2011-07-20 22:54 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Litvinov Sergey

[-- Attachment #1: Type: text/plain, Size: 75 bytes --]

ob-fortran.el: fix a bug with string input, add ob-fortran tests with
ert.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 7793 bytes --]

From ed4e14fd509cad8d9ccc66bef570f2d8796213ca Mon Sep 17 00:00:00 2001
From: Litvinov Sergey <slitvinov@gmail.com>
Date: Thu, 21 Jul 2011 00:44:50 +0200
Subject: [PATCH] ob-fortran.el: fix bug with string input, add ob-fortran tests with ert

---
 contrib/babel/langs/ob-fortran.el    |    4 +-
 testing/README.org                   |    1 +
 testing/examples/ob-fortran-test.org |   86 +++++++++++++++++++---------------
 testing/lisp/test-ob-fortran.el      |   80 +++++++++++++++++++++++++++++++
 4 files changed, 131 insertions(+), 40 deletions(-)
 create mode 100644 testing/lisp/test-ob-fortran.el

diff --git a/contrib/babel/langs/ob-fortran.el b/contrib/babel/langs/ob-fortran.el
index f2f5cb2..6b0b144 100644
--- a/contrib/babel/langs/ob-fortran.el
+++ b/contrib/babel/langs/ob-fortran.el
@@ -142,8 +142,8 @@ of the same value."
      ((or (characterp val))
       (format "character, parameter :: %S = '%S'\n" var val))
      ((stringp val)
-      (format "character, parameter ::  %S(%d) = '%s'\n"
-              var (length val) val))
+      (format "character(len=%d), parameter ::  %S = '%s'\n"
+              (length val) var val))
      ((listp val)
       (format "real, parameter :: %S(%d) = %s\n"
 	      var (length val) (ob-fortran-transform-list val)))
diff --git a/testing/README.org b/testing/README.org
index 648a30d..3cc0487 100644
--- a/testing/README.org
+++ b/testing/README.org
@@ -78,6 +78,7 @@ First tangle this file out to your desktop.
   (org-id-update-id-locations
    (list (concat org-dir "/testing/examples/babel.org")
          (concat org-dir "/testing/examples/normal.org")
+         (concat org-dir "/testing/examples/ob-fortran-test.org")
          (concat org-dir "/testing/examples/link-in-heading.org")
          (concat org-dir "/testing/examples/links.org")))
   
diff --git a/testing/examples/ob-fortran-test.org b/testing/examples/ob-fortran-test.org
index ade9f43..d48ae4e 100644
--- a/testing/examples/ob-fortran-test.org
+++ b/testing/examples/ob-fortran-test.org
@@ -1,76 +1,86 @@
-* Test org fortran file
-#+begin_src fortran
+#+Title: a collection of examples for ob-fortran tests
+#+OPTIONS: ^:nil
+
+* simple programs
+  :PROPERTIES:
+  :ID:       459384e8-1797-4f11-867e-dde0473ea7cc
+  :END:
+#+source: hello
+#+begin_src fortran :results silent
 print *, 'Hello world'
 #+end_src
 
-#+begin_src fortran
+#+source: fortran_parameter
+#+begin_src fortran :results silent
 integer, parameter :: i = 10
-print *, 'i = ', i
+write (*, '(i2)') i
 #+end_src
 
-#+begin_src fortran :var N = 10
-print *, 'N = ', N
+* variable resolution
+  :PROPERTIES:
+  :ID:       d8d1dfd3-5f0c-48fe-b55d-777997e02242
+  :END:
+#+begin_src fortran :var N = 15 :results silent
+write (*, '(i2)') N
 #+end_src
 
 Define for preprocessed fortran
-#+begin_src fortran :defines N 42
+#+begin_src fortran :defines N 42 :results silent
 implicit none
-print *, 'N = ', N
+write (*, '(i2)') N
 #+end_src
 
-#+begin_src fortran :var s="word"
-print *, 's = ', s
-print *, 'size(s) = ', size(s)
+#+begin_src fortran :var s="word" :results silent
+write (*, '(a4)') s
 #+end_src
-
-#+begin_src fortran :var s=42.0
-print *, 's = ', s
-print *, 'kind(s) = ', kind(s)
+* arrays
+  :PROPERTIES:
+  :ID:       c28569d9-04ce-4cad-ab81-1ea29f691465
+  :END:
+Real array as input
+#+begin_src fortran :var s='(1.0 2.0 3.0) :results silent
+write (*, '(3f5.2)'), s
 #+end_src
 
-#+begin_src fortran
-program ex
-print *, "output of ex program"
-end program ex
+#+tblname: test_tbl
+| 1.0 |
+| 2.0 |
+
+#+begin_src fortran :var s=test_tbl :results silent
+write (*, '(2f5.2)'), s
 #+end_src
 
+* failing
+  :PROPERTIES:
+  :ID:       891ead4a-f87a-473c-9ae0-1cf348bcd04f
+  :END:
 Should fail (TODO: add input variables for the case with explicit
 program statement)
-#+begin_src fortran :var s="word"
+#+begin_src fortran :var s="word" :results silent
 program ex
 print *, "output of ex program"
 end program ex
 #+end_src
 
-Real array as input
-#+begin_src fortran :var s='(1.0 2.0 3.0)
-print *, s
-#+end_src
-
-#+tblname: test_tbl
-| 1.0 |
-| 2.0 |
-
-Real array as input
-#+begin_src fortran :var s=test_tbl
-print *, s
-#+end_src
-
 Fails to compile (TODO: error check in ob-fortran.el)
-#+begin_src fortran :var s='(1 ())
+#+begin_src fortran :var s='(1 ()) :results silent
 print *, s
 #+end_src
 
 Should fail to compile with gfortran
-#+begin_src fortran :flags --std=f95 --pedantic-error
+#+begin_src fortran :flags --std=f95 --pedantic-error :results silent
 program ex
 integer*8 :: i
 end program ex
 #+end_src
 
+* programs input parameters
+  :PROPERTIES:
+  :ID:       2d5330ea-9934-4737-9ed6-e1d3dae2dfa4
+  :END:
 Pass parameters to the program
-#+begin_src fortran :cmdline "23"
+#+begin_src fortran :cmdline "23" :results silent
 character(len=255) :: cmd
-call get_command(cmd)
+call get_command_argument(1, cmd)
 write (*,*) trim(cmd)
 #+end_src
diff --git a/testing/lisp/test-ob-fortran.el b/testing/lisp/test-ob-fortran.el
new file mode 100644
index 0000000..b9ffbfd
--- /dev/null
+++ b/testing/lisp/test-ob-fortran.el
@@ -0,0 +1,80 @@
+(require 'ob-fortran)
+ 
+(ert-deftest ob-fortran/assert ()
+  (should t))
+
+(ert-deftest ob-fortran/simple-program ()
+  "Test of hello world program."
+  (org-test-at-id "459384e8-1797-4f11-867e-dde0473ea7cc"
+    (org-babel-next-src-block)
+    (should (equal "Hello world" (org-babel-execute-src-block))))
+)
+
+(ert-deftest ob-fortran/fortran-var-program ()
+  "Test a fortran variable"
+  (org-test-at-id "459384e8-1797-4f11-867e-dde0473ea7cc"
+    (org-babel-next-src-block 2)
+    (should (= 10 (org-babel-execute-src-block))))
+)
+
+(ert-deftest ob-fortran/input-var ()
+  "Test :var"
+  (org-test-at-id "d8d1dfd3-5f0c-48fe-b55d-777997e02242"
+    (org-babel-next-src-block)
+    (should (= 15 (org-babel-execute-src-block)))))
+
+(ert-deftest ob-fortran/preprosessor-var ()
+  "Test preprocessed fortran"
+  (org-test-at-id "d8d1dfd3-5f0c-48fe-b55d-777997e02242"
+    (org-babel-next-src-block 2)
+    (should (= 42 (org-babel-execute-src-block)))))
+
+(ert-deftest ob-fortran/character-var ()
+  "Test string input"
+  (org-test-at-id "d8d1dfd3-5f0c-48fe-b55d-777997e02242"
+    (org-babel-next-src-block 3)
+    (should (equal "word" (org-babel-execute-src-block)))))
+
+(ert-deftest ob-fortran/list-var ()
+  "Test real array input"
+  (org-test-at-id "c28569d9-04ce-4cad-ab81-1ea29f691465"
+    (org-babel-next-src-block)
+    (should (equal "1.00 2.00 3.00" (org-babel-execute-src-block)))))
+
+(ert-deftest ob-fortran/list-var-from-table ()
+  "Test real array from a table"
+  (org-test-at-id "c28569d9-04ce-4cad-ab81-1ea29f691465"
+    (org-babel-next-src-block 2)
+    (should (equal "1.00 2.00" (org-babel-execute-src-block)))))
+
+(ert-deftest ob-fortran/no-variables-with-main ()
+  "Test :var with explicit 'program'"
+  (org-test-at-id "891ead4a-f87a-473c-9ae0-1cf348bcd04f"
+    (org-babel-next-src-block)
+    (should-error (org-babel-execute-src-block))
+    :type 'error))
+
+;; (ert-deftest ob-fortran/wrong-list ()
+;;   "Test wrong input list"
+;;   (org-test-at-id "891ead4a-f87a-473c-9ae0-1cf348bcd04f"
+;;     (org-babel-next-src-block 2)
+;;     (should-error (org-babel-execute-src-block))
+;;     :type 'error))
+
+;; (ert-deftest ob-fortran/compiler-flags ()
+;;   "Test compiler's flags"
+;;   (org-test-at-id "891ead4a-f87a-473c-9ae0-1cf348bcd04f"
+;;     (org-babel-next-src-block 3)
+;;     (should-error (org-babel-execute-src-block))
+;;     :type 'error))
+
+(ert-deftest ob-fortran/command-arguments ()
+  "Test real array from a table"
+  (org-test-at-id "2d5330ea-9934-4737-9ed6-e1d3dae2dfa4"
+    (org-babel-next-src-block)
+    (should (= 23 (org-babel-execute-src-block)))))
+
+(provide 'test-ob-fortran)
+
+;;; test-ob-fortran.el ends here
+ 
-- 
1.7.4.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BABEL,PATCH] ob-fortran, ert tests
  2011-07-20 22:54 [BABEL,PATCH] ob-fortran, ert tests Litvinov Sergey
@ 2011-07-21  9:23 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2011-07-21  9:23 UTC (permalink / raw)
  To: Litvinov Sergey; +Cc: emacs-orgmode

Hi Sergey,

Litvinov Sergey <slitvinov@gmail.com> writes:

> ob-fortran.el: fix a bug with string input, add ob-fortran tests with
> ert.

Applied, thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-21  9:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-20 22:54 [BABEL,PATCH] ob-fortran, ert tests Litvinov Sergey
2011-07-21  9:23 ` Bastien

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).