Pārlūkot izejas kodu

Awk can be called with no in-file: and no :stdin

Litvinov Sergey 13 gadi atpakaļ
vecāks
revīzija
6b6ab13810

+ 2 - 4
lisp/ob-awk.el

@@ -26,8 +26,7 @@
 
 ;;; Commentary:
 
-;; Babel's awk support relies on two special header argument one of
-;; which is required to pass data to the awk process.
+;; Babel's awk can use special header argument:
 ;; 
 ;; - :in-file takes a path to a file of data to be processed by awk
 ;;   
@@ -89,11 +88,10 @@ called by `org-babel-execute-src-block'"
 	      (with-temp-file tmp (insert results))
 	      (org-babel-import-elisp-from-file tmp)))))
       (cond
-       (in-file (org-babel-eval cmd ""))
        (stdin (with-temp-buffer
 		(call-process-shell-command cmd stdin (current-buffer))
 		(buffer-string)))
-       (t (error "ob-awk: must specify either :in-file or :stdin"))))
+       (t (org-babel-eval cmd ""))))
      (org-babel-pick-name
       (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
      (org-babel-pick-name

+ 1 - 0
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-awk-test.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")))

+ 2 - 0
testing/examples/ob-awk-test.in

@@ -0,0 +1,2 @@
+ # an input file for awk test
+15

+ 39 - 0
testing/examples/ob-awk-test.org

@@ -0,0 +1,39 @@
+#+Title: a collection of examples for ob-awk tests
+#+OPTIONS: ^:nil
+
+* Simple tests
+  :PROPERTIES:
+  :ID:       9e998b2a-3581-43fe-b26d-07d3c507b86a
+  :END:
+Run without input stream
+#+begin_src awk :ouput silent :results silent
+  BEGIN {
+      print 42
+  }
+#+end_src
+
+Use a code block ouput as an input
+#+begin_src awk  :stdin genseq :results silent
+  {
+      print 42+$1
+  }
+#+end_src
+
+Use input file
+#+srcname: genfile
+#+begin_src awk  :in-file ob-awk-test.in :results silent
+    $0~/[\t]*#/{
+        # skip comments 
+        next
+    }
+    { 
+        print $1*10
+    }
+#+end_src
+
+* Input data generators
+A code block to generate input stream
+#+srcname: genseq
+#+begin_src emacs-lisp :results silent
+(print "1")
+#+end_src

+ 19 - 0
testing/lisp/test-ob-awk.el

@@ -0,0 +1,19 @@
+(require 'ob-awk)
+
+(ert-deftest ob-awk/input-none ()
+  "Test with no input file"
+  (org-test-at-id "9e998b2a-3581-43fe-b26d-07d3c507b86a"
+    (org-babel-next-src-block)
+    (should (= 42 (org-babel-execute-src-block)))))
+
+(ert-deftest ob-awk/input-src-block ()
+  "Test a code block as an input"
+  (org-test-at-id "9e998b2a-3581-43fe-b26d-07d3c507b86a"
+    (org-babel-next-src-block 2)
+    (should (= 43 (org-babel-execute-src-block)))))
+
+(ert-deftest ob-awk/input-src-block ()
+  "Test a code block as an input"
+  (org-test-at-id "9e998b2a-3581-43fe-b26d-07d3c507b86a"
+    (org-babel-next-src-block 3)
+    (should (= 150 (org-babel-execute-src-block)))))