summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-03-15 01:27:52 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-03-15 01:27:52 -0400
commit87ad6f52f8089d9cd8a9ba3889151ad835a8dd0a (patch)
treefcb203476886db20f493e10136699b09743d0d20
parenta5d99cc9d37d8e58bc06aa70a40d0247b9da820e (diff)
downloadfork-ledger-87ad6f52f8089d9cd8a9ba3889151ad835a8dd0a.tar.gz
fork-ledger-87ad6f52f8089d9cd8a9ba3889151ad835a8dd0a.tar.bz2
fork-ledger-87ad6f52f8089d9cd8a9ba3889151ad835a8dd0a.zip
ldg-texi.el now auto-generates regression tests
-rw-r--r--doc/ledger.texi15
-rw-r--r--lisp/ldg-texi.el67
2 files changed, 64 insertions, 18 deletions
diff --git a/doc/ledger.texi b/doc/ledger.texi
index 6573a066..10e80a60 100644
--- a/doc/ledger.texi
+++ b/doc/ledger.texi
@@ -4107,4 +4107,19 @@ parser_t
@section General Utility
+@c data: foo
+@smallexample
+2004/05/01 * Checking balance
+ Assets:Bank:Checking $1,000.00
+ Equity:Opening Balances
+@end smallexample
+
+@c smex utility-1: $LEDGER -f $foo bal
+@smallexample
+ $1,000.00 Assets:Bank:Checking
+ $-1,000.00 Equity:Opening Balances
+--------------------
+ 0
+@end smallexample
+
@bye
diff --git a/lisp/ldg-texi.el b/lisp/ldg-texi.el
index b621ee83..0810369b 100644
--- a/lisp/ldg-texi.el
+++ b/lisp/ldg-texi.el
@@ -2,14 +2,16 @@
(defvar ledger-sample-doc-path "/Users/johnw/src/ledger/doc/sample.dat")
(defvar ledger-normalization-args "--args-only --columns 80")
-(defun ledger-texi-expand-examples ()
+(defun ledger-texi-update-examples ()
(interactive)
(save-excursion
(goto-char (point-min))
- (while (re-search-forward "^@c \\(\\(?:small\\)?example\\): \\(.*\\)" nil t)
+ (while (re-search-forward "^@c \\(\\(?:sm\\)?ex\\) \\(\\S-+\\): \\(.*\\)" nil t)
(let ((section (match-string 1))
- (command (match-string 2))
- (data-file ledger-sample-doc-path))
+ (example-name (match-string 2))
+ (command (match-string 3)) expanded-command
+ (data-file ledger-sample-doc-path)
+ input output)
(goto-char (match-end 0))
(forward-line)
(when (looking-at "@\\(\\(?:small\\)?example\\)")
@@ -28,35 +30,64 @@
(search-forward (format "@c data: %s" label))
(re-search-forward "@\\(\\(?:small\\)?example\\)")
(forward-line)
- (let ((beg (point))
- content)
+ (let ((beg (point)))
(re-search-forward "@end \\(\\(?:small\\)?example\\)")
- (setq content (buffer-substring-no-properties
+ (setq input (buffer-substring-no-properties
beg (match-beginning 0)))
(with-current-buffer (find-file-noselect data-file)
(erase-buffer)
- (insert content)
+ (insert input)
(save-buffer))))))
- (if (string-match "\\$LEDGER" command)
- (setq command
+ (setq expanded-command command)
+ (if (string-match "\\$LEDGER" expanded-command)
+ (setq expanded-command
(replace-match
(format "%s -f \"%s\" %s" ledger-path
data-file ledger-normalization-args)
- t t command)))
+ t t expanded-command)))
(save-restriction
(narrow-to-region (point) (point))
- (shell-command command t (get-buffer-create " *ldg-texi*"))
+ (shell-command expanded-command t (get-buffer-create " *ldg-texi*"))
(if (= (point-min) (point-max))
(progn
(push-mark nil t)
(message "Command '%s' yielded no result at %d"
- command (point))
+ expanded-command (point))
(ding))
+ (setq output (buffer-string))
(goto-char (point-min))
- (insert "@" section ?\n)
- (goto-char (point-max))
- (unless (eolp)
- (insert ?\n))
- (insert "@end " section ?\n)))))))
+ (let ((section-name (if (string= section "smex")
+ "smallexample"
+ "example")))
+ (insert "@" section-name ?\n)
+ (goto-char (point-max))
+ (unless (eolp)
+ (insert ?\n))
+ (insert "@end " section-name ?\n))))
+
+ ;; Update the regression test associated with this example
+
+ (with-current-buffer
+ (find-file-noselect
+ (expand-file-name (concat example-name ".test")
+ "../test/manual"))
+ (erase-buffer)
+ (let ((case-fold-search nil))
+ (if (string-match "\\$LEDGER\\s-+" command)
+ (setq command (replace-match "" t t command)))
+ (if (string-match " -f \\$\\([-a-z]+\\)" command)
+ (setq command (replace-match "" t t command))))
+
+ (insert command ?\n)
+ (insert "<<<" ?\n)
+ (insert input)
+ (insert ">>>1" ?\n)
+ (insert output)
+ (insert ">>>2" ?\n)
+ (insert "=== 0" ?\n)
+ (save-buffer)
+ (kill-buffer (current-buffer)))))))
+
+(provide 'ldg-texi)