@@ -1861,17 +1861,19 @@ The test policy is defined by a trio of settings, see docs for these variables:
1861
1861
(interactive )
1862
1862
(if perlnow-trace (perlnow-message " Calling perlnow-edit-test-file" ))
1863
1863
(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
+
1875
1877
1876
1878
; ; Used by: perlnow-edit-test-file, perlnow-test-create-manually, perlnow-select-create-test
1877
1879
(defun perlnow-open-test-file (testfile )
@@ -2803,14 +2805,6 @@ Does the simplest possible check: looks for a *.t extension on file name."
2803
2805
))
2804
2806
ret))
2805
2807
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
-
2814
2808
(defun perlnow-module-code-p ()
2815
2809
" Determine if the buffer looks like a perl module.
2816
2810
This looks for the package line near the top.
@@ -3115,8 +3109,7 @@ An example of returned metadata.
3115
3109
(mapconcat 'identity (split-string package-name " ::" ) " -" ))
3116
3110
)
3117
3111
3118
- ((perlnow-test-p) ; ; EXPERIMENTAL needs test
3119
-
3112
+ ((perlnow-test-p)
3120
3113
(setq file-location
3121
3114
(file-name-directory (buffer-file-name )))
3122
3115
@@ -3179,6 +3172,7 @@ An example of returned metadata.
3179
3172
(goto-char initial-point)
3180
3173
ret-list))
3181
3174
3175
+
3182
3176
(defun perlnow-get-package-name-from-module-buffer ()
3183
3177
" Get the module name from the first package line.
3184
3178
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
4088
4082
4089
4083
; ;; TODO check if this is limited to cpan-style
4090
4084
; ;; 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 )
4092
4086
" Looks for test files appropriate for the current file.
4093
4087
Uses the three given elements of a \" test policy\" , to find
4094
4088
appropriate test files:
@@ -4097,32 +4091,57 @@ is defined by three pieces of information:
4097
4091
the TESTLOC \( see `perlnow-test-policy-test-location' \)
4098
4092
the DOTDEF \( see `perlnow-test-policy-dot-definition' \)
4099
4093
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."
4101
4096
(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
4103
4098
(message " perlnow-list-test-files, looking at buffer: %s " (buffer-name ))
4104
- (let* ((file-location
4099
+ (let* ((full-file
4105
4100
(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 )))
4108
4104
; ; module oriented info (calculated below):
4109
4105
package-name inc-spot hyphenized-package-name
4110
4106
; ; need to determine:
4111
4107
testloc-absolute test-file-list
4112
4108
)
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
+
4113
4121
; ; 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 ))
4119
4133
4120
4134
(setq testloc-absolute
4121
4135
(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
+ )
4126
4145
(t
4127
4146
(error (concat
4128
4147
" Invalid perlnow-test-policy-dot-definition, "
@@ -4131,7 +4150,7 @@ Returns file names with full path if FULLPATH is t."
4131
4150
(unless (file-directory-p testloc-absolute)
4132
4151
(message " warning %s is not a directory " testloc-absolute))
4133
4152
(setq test-file-list
4134
- (directory-files testloc-absolute fullpath " \\ \. t$" ))
4153
+ (directory-files testloc-absolute fullpath-opt " \\ \. t$" ))
4135
4154
test-file-list))
4136
4155
4137
4156
; ; Adding "harder" awareness to: perlnow-edit-test-file
@@ -4345,9 +4364,7 @@ This only checks the first character in NAME."
4345
4364
; ; The code buffer the menu was generated from
4346
4365
(setq initiating-buffer perlnow-associated-code)
4347
4366
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))
4351
4368
4352
4369
; ; trace associated pointers back to code being tested
4353
4370
(setq original-context
@@ -4399,6 +4416,19 @@ This only checks the first character in NAME."
4399
4416
(replace-regexp-in-string " \s +$" " " selected-file))
4400
4417
selected-file)))
4401
4418
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))
4402
4432
4403
4433
; ; bind this to "a" in perlnow-select-mode
4404
4434
; ; Note: somewhat similar to perlnow-test-create-manually
@@ -4650,7 +4680,75 @@ falls back to just \"perl\"."
4650
4680
(setq how-to-perl " perl" )))
4651
4681
how-to-perl))
4652
4682
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 ()
4654
4752
" Determines if the current file buffer is located in an cpan-style tree.
4655
4753
Should return the path to the current cpan-style staging area, or nil
4656
4754
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\"\)."
4702
4800
(t
4703
4801
(setq return nil )))
4704
4802
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?
4706
4804
(if return ; ; skip if nothing found (note, that means dir is "/")
4707
4805
(perlnow-cpan-style-build dir))
4708
4806
4709
4807
; ; (message "perlnow-find-cpan-style-staging-area return: %s" return);; DEBUG
4710
- return
4711
- ) ; ; end let*
4712
- ) ; ; end defun
4808
+ return))
4713
4809
4714
4810
4715
4811
; ; replaces perlnow-run-perl-makefile-pl-if-needed & perlnow-run-perl-build-pl
@@ -5514,7 +5610,7 @@ Defaults to perlnow-t-for-code-plist."
5514
5610
(setq perlnow-t-for-code-plist plist) ; ; TODO temporary fix
5515
5611
)
5516
5612
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.
5518
5614
(defun perlnow-plist-keys ( plist )
5519
5615
" Return all keys of the given plist as a list of strings."
5520
5616
; ; Step through a list and skipping the even values
@@ -6080,6 +6176,43 @@ It does three things:
6080
6176
(perlnow-troff)
6081
6177
)
6082
6178
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
+
6083
6216
(defun perlnow-wtf ()
6084
6217
" "
6085
6218
(interactive )
@@ -6091,7 +6224,6 @@ It does three things:
6091
6224
; ; EXPERIMENTAL
6092
6225
(perlnow-stash-put testloc-absolute inc-spot)
6093
6226
6094
-
6095
6227
(message " perlnow-t-for-code-plist: %s \n "
6096
6228
(pp perlnow-t-for-code-plist))
6097
6229
))
@@ -6101,18 +6233,6 @@ It does three things:
6101
6233
; ;-------
6102
6234
; ; debugging routines
6103
6235
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
-
6116
6236
(defun perlnow-tron ()
6117
6237
(interactive )
6118
6238
" Turns on trace and debug and writes a marker in *Messages*."
0 commit comments