Browse Source

awk code blocks handle tabular input

  Protected by a new unit test.

* lisp/ob-awk.el (org-babel-execute:awk): Use the
  `org-babel-awk-var-to-awk' function instead of a simple format
  string.
Eric Schulte 5 years ago
parent
commit
c3e497f394
3 changed files with 16 additions and 2 deletions
  1. 4 2
      lisp/ob-awk.el
  2. 7 0
      testing/examples/ob-awk-test.org
  3. 5 0
      testing/lisp/test-ob-awk.el

+ 4 - 2
lisp/ob-awk.el

@@ -70,8 +70,10 @@ called by `org-babel-execute-src-block'"
 			  (list org-babel-awk-command
 				"-f" code-file cmd-line)
 			  (mapcar (lambda (pair)
-				    (format "-v %s=%s"
-					    (cadr pair) (cddr pair)))
+				    (format "-v %s='%s'"
+					    (cadr pair)
+					    (org-babel-awk-var-to-awk
+					     (cddr pair))))
 				  (org-babel-get-header params :var))
 			  (list in-file))
 			 " ")))

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

@@ -31,6 +31,13 @@ Use input file
     }
 #+end_src
 
+#+name: awk-table-input
+| a | b | c |
+
+#+begin_src awk :var a=awk-table-input
+  BEGIN{ print a; }
+#+end_src
+
 * Input data generators
 A code block to generate input stream
 #+name: genseq

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

@@ -41,3 +41,8 @@
     (org-babel-next-src-block 3)
     (should (= 150 (org-babel-execute-src-block)))))
 
+(ert-deftest ob-awk/tabular-input ()
+  "Test a code block as an input"
+  (org-test-at-id "9e998b2a-3581-43fe-b26d-07d3c507b86a"
+    (org-babel-next-src-block 4)
+    (should (equal '(("a" "b" "c")) (org-babel-execute-src-block)))))