Skip to content

Commit 477c0ba

Browse files
committed
Two new tests:
13-perlnow-guess-run-string-with-milla.t 36-perlnow-perlnow-list-test-files.t perlnow-edit-test-file now works non-interactively with optional testfile argument. Worked on perlnow-list-test-files Added new error message: "Could not determine inc-spot for file:" Modified to work with different contexts such as a test select buffer: perlnow-find-cpan-style-staging-area Revised all tests to use a new test-init function that does basic initialization including creating test subdirectories named using the tests numeric prefix.
1 parent 860d15f commit 477c0ba

20 files changed

+2020
-1696
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*~
2+
\#*#
3+
Build
4+
_build
5+
.rep
6+
MYMETA.yml
7+
MANIFEST.SKIP
8+
Emacs-Rep-*.tar.gz
9+
META.yml
10+
blib
11+
Makefile.PL
12+
Makefile
13+
Old
14+
*.BAK.el
15+
.gitignore
16+
.hidden

elisp/perlnow.el

Lines changed: 179 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,17 +1861,19 @@ The test policy is defined by a trio of settings, see docs for these variables:
18611861
(interactive)
18621862
(if perlnow-trace (perlnow-message "Calling perlnow-edit-test-file"))
18631863
(let* ((harder-setting (car current-prefix-arg)))
1864-
(unless testfile
1865-
(cond (harder-setting ;; if so, perlnow-select-file has to handle open, etc
1866-
(perlnow-edit-test-file-harder harder-setting))
1867-
(t
1868-
(setq testfile
1869-
(perlnow-get-test-file-name))
1870-
(setq perlnow-recent-pick testfile)
1871-
(setq perlnow-recent-pick-global testfile) ;; TODO experimental
1872-
(perlnow-open-test-file testfile)
1873-
)))
1874-
))
1864+
(cond (harder-setting ;; if so, perlnow-select-file has to handle open, etc
1865+
(perlnow-edit-test-file-harder harder-setting))
1866+
(t
1867+
(cond ((not testfile)
1868+
(setq testfile
1869+
(perlnow-get-test-file-name))
1870+
(setq perlnow-recent-pick testfile)
1871+
(setq perlnow-recent-pick-global testfile) ;; TODO experimental
1872+
))
1873+
(message "ZANG: about to perlnow-open-test-file with: %s" testfile)
1874+
(perlnow-open-test-file testfile)
1875+
))))
1876+
18751877

18761878
;; Used by: perlnow-edit-test-file, perlnow-test-create-manually, perlnow-select-create-test
18771879
(defun perlnow-open-test-file (testfile)
@@ -2803,14 +2805,6 @@ Does the simplest possible check: looks for a *.t extension on file name."
28032805
))
28042806
ret))
28052807

2806-
(defun perlnow-report-script-p ()
2807-
"Report whether the current buffer looks like a perl script."
2808-
(interactive)
2809-
(if perlnow-trace (perlnow-message "Calling perlnow-report-script-p"))
2810-
(if (perlnow-script-p)
2811-
(message "script!")
2812-
(message "not.")))
2813-
28142808
(defun perlnow-module-code-p ()
28152809
"Determine if the buffer looks like a perl module.
28162810
This looks for the package line near the top.
@@ -3115,8 +3109,7 @@ An example of returned metadata.
31153109
(mapconcat 'identity (split-string package-name "::") "-"))
31163110
)
31173111

3118-
((perlnow-test-p) ;; EXPERIMENTAL needs test
3119-
3112+
((perlnow-test-p)
31203113
(setq file-location
31213114
(file-name-directory (buffer-file-name)))
31223115

@@ -3179,6 +3172,7 @@ An example of returned metadata.
31793172
(goto-char initial-point)
31803173
ret-list))
31813174

3175+
31823176
(defun perlnow-get-package-name-from-module-buffer ()
31833177
"Get the module name from the first package line.
31843178
This will be in perl's double colon separated form, or it will
@@ -4088,7 +4082,7 @@ The template used is specified by the variable `perlnow-perl-test-module-templat
40884082

40894083
;;; TODO check if this is limited to cpan-style
40904084
;;; TODO somewhere need to be able to do recursive decent through a project tree
4091-
(defun perlnow-list-test-files (testloc dotdef namestyle &optional fullpath)
4085+
(defun perlnow-list-test-files (testloc dotdef namestyle &optional fullpath-opt)
40924086
"Looks for test files appropriate for the current file.
40934087
Uses the three given elements of a \"test policy\", to find
40944088
appropriate test files:
@@ -4097,32 +4091,57 @@ is defined by three pieces of information:
40974091
the TESTLOC \(see `perlnow-test-policy-test-location'\)
40984092
the DOTDEF \(see `perlnow-test-policy-dot-definition' \)
40994093
and the NAMESTYLE \(see `perlnow-test-policy-naming-style'\).
4100-
Returns file names with full path if FULLPATH is t."
4094+
Note: actually NAMESTYLE isn't used internally: just a placeholder.
4095+
Returns file names with full path if FULLPATH-OPT is t."
41014096
(if perlnow-trace (perlnow-message "Calling perlnow-list-test-files"))
4102-
;;; Note, code mutated from above: perlnow-test-from-policy
4097+
;;;; Note, code mutated from above: perlnow-test-from-policy
41034098
(message "perlnow-list-test-files, looking at buffer: %s" (buffer-name))
4104-
(let* ((file-location
4099+
(let* ((full-file
41054100
(file-name-directory (buffer-file-name)))
4106-
(basename
4107-
(file-name-sans-extension (file-name-nondirectory (buffer-file-name))))
4101+
;; (basename
4102+
;; (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))
4103+
(basename (file-name-base (buffer-file-name)))
41084104
;; module oriented info (calculated below):
41094105
package-name inc-spot hyphenized-package-name
41104106
;; need to determine:
41114107
testloc-absolute test-file-list
41124108
)
4109+
(unless full-file ;; TODO but what about test select menu? Or even, dired?
4110+
(error "perlnow-list-test-files: buffer has no associated file, giving up."))
4111+
4112+
;; check whether curbuff is perl code? (Why not run metadata probe)
4113+
;; perlnow-find-cpan-style-staging-area
4114+
;; perlnow-script-p
4115+
;; perlnow-test-p
4116+
;; perlnow-test-select-menu-p
4117+
4118+
;; (defun perlnow-get-inc-spot (package-name pm-location)
4119+
4120+
41134121
;; module oriented info
4114-
(cond
4115-
((setq package-name (perlnow-get-package-name-from-module-buffer))
4116-
(setq inc-spot (perlnow-get-inc-spot package-name file-location))
4117-
(setq hyphenized-package-name (mapconcat 'identity (split-string package-name "::") "-"))
4118-
))
4122+
(cond ((setq package-name (perlnow-get-package-name-from-module-buffer))
4123+
(setq inc-spot (perlnow-get-inc-spot package-name full-file))
4124+
(setq hyphenized-package-name
4125+
(mapconcat 'identity (split-string package-name "::") "-"))
4126+
)
4127+
;; (t ;; handle non-module case
4128+
;; )
4129+
)
4130+
4131+
(if perlnow-debug
4132+
(message "perlnow-list-test-files: full-file: %s testloc: %s " full-file testloc ))
41194133

41204134
(setq testloc-absolute
41214135
(perlnow-fixdir
4122-
(cond ((string= dotdef "fileloc") ; might be script or module
4123-
(perlnow-expand-dots-relative-to file-location testloc))
4124-
((string= dotdef "incspot") ; only defined with modules
4125-
(perlnow-expand-dots-relative-to inc-spot testloc))
4136+
(cond ((string= dotdef "fileloc") ;; may be for script or module
4137+
(perlnow-expand-dots-relative-to full-file testloc))
4138+
((string= dotdef "incspot") ;; only defined with modules
4139+
(cond (inc-spot
4140+
(perlnow-expand-dots-relative-to inc-spot testloc))
4141+
(t
4142+
(error (format "Could not determine inc-spot for file: %s" full-file))
4143+
))
4144+
)
41264145
(t
41274146
(error (concat
41284147
"Invalid perlnow-test-policy-dot-definition, "
@@ -4131,7 +4150,7 @@ Returns file names with full path if FULLPATH is t."
41314150
(unless (file-directory-p testloc-absolute)
41324151
(message "warning %s is not a directory" testloc-absolute))
41334152
(setq test-file-list
4134-
(directory-files testloc-absolute fullpath "\\\.t$"))
4153+
(directory-files testloc-absolute fullpath-opt "\\\.t$"))
41354154
test-file-list))
41364155

41374156
;; Adding "harder" awareness to: perlnow-edit-test-file
@@ -4345,9 +4364,7 @@ This only checks the first character in NAME."
43454364
;; The code buffer the menu was generated from
43464365
(setq initiating-buffer perlnow-associated-code)
43474366

4348-
(setq selected-file-compact (perlnow-select-file-from-current-line))
4349-
(setq path (perlnow-get-path-from-markedup-name selected-file-compact))
4350-
(setq selected-file (concat path selected-file-compact))
4367+
(setq selected-file (perlnow-select-read-full-file-name))
43514368

43524369
;; trace associated pointers back to code being tested
43534370
(setq original-context
@@ -4399,6 +4416,19 @@ This only checks the first character in NAME."
43994416
(replace-regexp-in-string "\s+$" "" selected-file))
44004417
selected-file)))
44014418

4419+
;; Used indirectly by perlnow-select-file
4420+
(defun perlnow-select-read-full-file-name ()
4421+
"In select test buffer, tries to read a file name with path from current line.
4422+
Returns nil if not inside a *perlnow test select* buffer, or if
4423+
no file-name is found on the current line."
4424+
(let (selected-file-compact path selected-file)
4425+
(cond ((perlnow-test-select-menu-p)
4426+
(setq selected-file-compact (perlnow-select-file-from-current-line))
4427+
(cond ((or selected-file-compact (not (string= selected-file-compact "")))
4428+
(setq path (perlnow-get-path-from-markedup-name selected-file-compact))
4429+
(setq selected-file (concat path selected-file-compact))))
4430+
))
4431+
selected-file))
44024432

44034433
;; bind this to "a" in perlnow-select-mode
44044434
;; Note: somewhat similar to perlnow-test-create-manually
@@ -4650,7 +4680,75 @@ falls back to just \"perl\"."
46504680
(setq how-to-perl "perl")))
46514681
how-to-perl))
46524682

4653-
(defun perlnow-find-cpan-style-staging-area ()
4683+
(defun perlnow-find-cpan-style-staging-area ( &optional file-name )
4684+
"Determines if the current file buffer is located in an cpan-style tree.
4685+
Should return the path to the current cpan-style staging area, or
4686+
nil if it's not found. The staging area is located by searching
4687+
upwards from the location of a file to a location with files that
4688+
look like a cpan-style project (as currently implemented, it
4689+
looks for either a \"Makefile.PL\" or a \"Build.PL\"\).
4690+
This defaults to working on the current buffer's file \(if available\),
4691+
but can use the optional FILE-NAME instead. For the special case of a
4692+
\"*perlnow select test*\" buffer, it works with a file name extracted
4693+
from the buffer." ;; TODO specify how?
4694+
;; Two important cases to cover are:
4695+
;; ~/perldev/Horror-Grossout/lib/Horror/Grossout.pm
4696+
;; ~/perldev/Horror-Grossout/t/Horror-Grossout.t
4697+
(interactive)
4698+
(if perlnow-trace (perlnow-message "Calling perlnow-find-cpan-style-staging-area"))
4699+
(let* (
4700+
return
4701+
;; args for directory-files function:
4702+
(dir "") ;; candidate directory under examination
4703+
(full-names nil)
4704+
(pattern "^[ltMB]") ;; to pre-screen listing for interesting results only
4705+
;; lib, t, Makefile.PL, Build.PL, etc
4706+
(nosort t )
4707+
(file-list () ) ;; file listing of the candidate directory (pre-screened)
4708+
;;
4709+
(buffy (buffer-file-name))
4710+
(pnts-file (perlnow-select-read-full-file-name)) ;; nil if not select test buffer
4711+
(input-file
4712+
(or file-name buffy pnts-file perlnow-associated-code perlnow-recent-pick-global))
4713+
)
4714+
(cond (input-file
4715+
(setq dir (perlnow-fixdir (file-name-directory input-file)))
4716+
;; Look at dir, and each level above it, stepping up one each time,
4717+
;; give up when dir is so short we must be at root (( TODO but: Windows? ))
4718+
(setq return
4719+
(catch 'UP
4720+
(while (> (length dir) 1)
4721+
(setq file-list (directory-files dir full-names pattern nosort))
4722+
4723+
(dolist (file file-list)
4724+
(if (or
4725+
(string= file "Makefile.PL")
4726+
(string= file "Build.PL")) ;; we found it!
4727+
(throw 'UP dir))
4728+
) ;; end dolist
4729+
4730+
;; go up a directory level
4731+
(setq dir (perlnow-fixdir (concat dir "..")))
4732+
;; if we can't read files here, give up
4733+
(if (not (file-accessible-directory-p dir))
4734+
(throw 'UP nil))
4735+
4736+
) ;; end while
4737+
nil ) ;; end catch, ran the gauntlet without success, so return nil
4738+
) ;; end setq return
4739+
)
4740+
(t
4741+
(setq return nil)))
4742+
4743+
;; TODO this func is supposed to *find*, why do a build as a side-effect?
4744+
(if return ;; skip if nothing found (note, that means dir is "/")
4745+
(perlnow-cpan-style-build dir))
4746+
4747+
(if perlnow-debug
4748+
(message "perlnow-find-cpan-style-staging-area return: %s" return))
4749+
return))
4750+
4751+
(defun perlnow-find-cpan-style-staging-area-OLD ()
46544752
"Determines if the current file buffer is located in an cpan-style tree.
46554753
Should return the path to the current cpan-style staging area, or nil
46564754
if it's not found. The staging area is located by searching upwards
@@ -4702,14 +4800,12 @@ for either a \"Makefile.PL\" or a \"Build.PL\"\)."
47024800
(t
47034801
(setq return nil)))
47044802

4705-
;; TODO this method is supposed to do a find, why is it doing a build as a side-effect?
4803+
;; TODO this func is supposed to *find*, why do a build as a side-effect?
47064804
(if return ;; skip if nothing found (note, that means dir is "/")
47074805
(perlnow-cpan-style-build dir))
47084806

47094807
;; (message "perlnow-find-cpan-style-staging-area return: %s" return);; DEBUG
4710-
return
4711-
) ;; end let*
4712-
) ;; end defun
4808+
return))
47134809

47144810

47154811
;; replaces perlnow-run-perl-makefile-pl-if-needed & perlnow-run-perl-build-pl
@@ -5514,7 +5610,7 @@ Defaults to perlnow-t-for-code-plist."
55145610
(setq perlnow-t-for-code-plist plist) ;; TODO temporary fix
55155611
)
55165612

5517-
;; It's hard to believe I needed to write this.
5613+
;; Like perl's "keys". It's hard to believe I needed to write this.
55185614
(defun perlnow-plist-keys ( plist )
55195615
"Return all keys of the given plist as a list of strings."
55205616
;; Step through a list and skipping the even values
@@ -6080,6 +6176,43 @@ It does three things:
60806176
(perlnow-troff)
60816177
)
60826178

6179+
(defun perlnow-report-script-p ()
6180+
"Report whether the current buffer looks like a perl script."
6181+
(interactive)
6182+
(if perlnow-trace (perlnow-message "Calling perlnow-report-script-p"))
6183+
(if (perlnow-script-p)
6184+
(message "script!")
6185+
(message "not.")))
6186+
6187+
6188+
(defun perlnow-report-sub-at-point ()
6189+
"Echoes the output from of \[[perlnow-sub-at-point]]."
6190+
(interactive)
6191+
(message "sub-at-point: %s" (perlnow-sub-at-point)))
6192+
6193+
(defun perlnow-report-buffer-name ()
6194+
""
6195+
(interactive)
6196+
(message "buffer-name: %s" (buffer-name))
6197+
)
6198+
6199+
(defun perlnow-report-list-test-files ()
6200+
"Command that lists test files associated with current buffer.
6201+
For do debugging trial runs."
6202+
(interactive)
6203+
(let ((testloc "../t")
6204+
(dotdef "incspot")
6205+
(namestyle "")
6206+
(fullpath-opt nil)
6207+
)
6208+
6209+
(message "perlnow-list-test-files: %s"
6210+
(pp
6211+
(perlnow-list-test-files testloc dotdef namestyle fullpath-opt)
6212+
))
6213+
))
6214+
6215+
60836216
(defun perlnow-wtf ()
60846217
""
60856218
(interactive)
@@ -6091,7 +6224,6 @@ It does three things:
60916224
;; EXPERIMENTAL
60926225
(perlnow-stash-put testloc-absolute inc-spot)
60936226

6094-
60956227
(message "perlnow-t-for-code-plist: %s\n"
60966228
(pp perlnow-t-for-code-plist))
60976229
))
@@ -6101,18 +6233,6 @@ It does three things:
61016233
;;-------
61026234
;; debugging routines
61036235

6104-
(defun perlnow-report-sub-at-point ()
6105-
"Echoes the output from of \[[perlnow-sub-at-point]]."
6106-
(interactive)
6107-
(message "sub-at-point: %s" (perlnow-sub-at-point)))
6108-
6109-
(defun perlnow-report-buffer-name ()
6110-
""
6111-
(interactive)
6112-
(message "buffer-name: %s" (buffer-name))
6113-
)
6114-
6115-
61166236
(defun perlnow-tron ()
61176237
(interactive)
61186238
"Turns on trace and debug and writes a marker in *Messages*."

0 commit comments

Comments
 (0)