ob-fortran.el: fix a bug with string input, add ob-fortran tests with
ert.
From ed4e14fd509cad8d9ccc66bef570f2d8796213ca Mon Sep 17 00:00:00 2001
From: Litvinov Sergey slitvi...@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