* Re: ERT indentation testing
@ 2011-06-02 12:37 Alan Mackenzie
2011-06-02 14:23 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Alan Mackenzie @ 2011-06-02 12:37 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: emacs-devel
Hi, Ted.
On 19th May 2011, you wrote:
>>> This can be done with ERT, right? A bunch of .cc files with file-local
>>> variables could be indented "properly" for those variables. Then the
>>> test logic for each file is
>SM> [...]
>>> Plus, of course, it's not limited to .cc files. It would work just as
>>> well for .c, .pl, .el, whatever.
>SM> Yup, we already have such files in test/indent.
>Yes, I see that now (I didn't see the commit for those, cool!)
>We should have .c and .cc files with the major indentation styles
>specified as file-local variables, plus .ini, Perl, Java, Python, and of
>course Lisp (CL and ELisp). Should I add those?
>>> I can write the ERT wrapper if this sounds useful.
>SM> If you could integrate test/indent with ERT's automated tests, that
>SM> would be nice.
>OK, I'll put it on my TODO list.
You are aware that there's an extensive test suite for CC Mode's
indentation (and font locking). It's in the tests directory of CC Mode's
CVS repository, which can be downloaded from
http://cc-mode.sourceforge.net/. Look for the file 000tests.el.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-02 12:37 ERT indentation testing Alan Mackenzie
@ 2011-06-02 14:23 ` Ted Zlatanov
2011-06-03 11:48 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-02 14:23 UTC (permalink / raw)
To: emacs-devel
On Thu, 2 Jun 2011 12:37:33 +0000 Alan Mackenzie <acm@muc.de> wrote:
AM> You are aware that there's an extensive test suite for CC Mode's
AM> indentation (and font locking). It's in the tests directory of CC Mode's
AM> CVS repository, which can be downloaded from
AM> http://cc-mode.sourceforge.net/. Look for the file 000tests.el.
I can't access that repository at the moment. Is there a mirror I can
use over HTTP, e.g. Git or Bazaar?
I didn't know that these tests existed. Why not simply integrate them
in the Emacs tests? Are they too specific?
A general indentation and font-locking tester is very useful, so if we
can generalize this code, it would be wonderful.
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-02 14:23 ` Ted Zlatanov
@ 2011-06-03 11:48 ` Ted Zlatanov
0 siblings, 0 replies; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-03 11:48 UTC (permalink / raw)
To: emacs-devel
On Thu, 02 Jun 2011 09:23:41 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> On Thu, 2 Jun 2011 12:37:33 +0000 Alan Mackenzie <acm@muc.de> wrote:
AM> You are aware that there's an extensive test suite for CC Mode's
AM> indentation (and font locking). It's in the tests directory of CC Mode's
AM> CVS repository, which can be downloaded from
AM> http://cc-mode.sourceforge.net/. Look for the file 000tests.el.
TZ> I didn't know that these tests existed. Why not simply integrate them
TZ> in the Emacs tests? Are they too specific?
TZ> A general indentation and font-locking tester is very useful, so if we
TZ> can generalize this code, it would be wonderful.
I looked at the code and it could be useful. But it has no notion of
ERT testing and consists of very specific code to force and test
font-lock and indentation. So it would be a lot of work to generalize
it (or parts of it) and integrate it with the GNU Emacs indentation
tests. It may be worthwhile nevertheless.
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation
@ 2011-05-17 23:21 Nix
2011-05-18 0:17 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Nix @ 2011-05-17 23:21 UTC (permalink / raw)
To: emacs-devel
Here's an experiment for you.
Visit a .c file in c-mode, with 'c-old-style-variable-behavior' set to
its default value of 'nil'. Set the style to something other than 'gnu'
with 'c-set-style' (make it something with a different
'c-basic-offset'). Look at 'c-basic-offset'. It's changed. Great!
Now. Add that same c-file-style as a file-local or directory-local
variable to that other style. Reopen it. 'c-basic-offset' hasn't changed
from the 'gnu' default, but 'c-indentation-style' proclaims that the
style has in fact been set. In fact, 'c-basic-offset' is permanently
stuck at the value specified for 'gnu', no matter what style you asked
for. And this is true for every single variable that is set by the 'gnu'
style, and for the pieces of 'c-offsets-alist' as well.
What's going on?
The problem is in 'c-set-style-1', where variables other than
'c-offsets-alist' and 'c-special-indent-hook' are treated specially:
;; all other variables
(t (when (or (not dont-override)
(not (memq attr c-style-variables))
(eq (if (eq dont-override t)
(symbol-value attr)
(default-value attr))
'set-from-style))
(set attr val)
The 'set-from-style' stuff is implementing the DONT-OVERRIDE parameter
to c-set-style, which is annoyingly described only in terms of what it
does, not what it's intended for:
,----
| If DONT-OVERRIDE is neither nil nor t, style variables whose default values
| have been set (more precisely, whose default values are not the symbol
| `set-from-style') will not be changed. This avoids overriding global settings
| done in ~/.emacs. It is useful to call c-set-style from a mode hook in this
| way.
|
| If DONT-OVERRIDE is t, style variables that already have values (i.e., whose
| values are not the symbol `set-from-style') will not be overridden. CC Mode
| calls c-set-style internally in this way whilst initializing a buffer; if
| cc-set-style is called like this from anywhere else, it will usually behave as
| a null operation.
`----
DONT-OVERRIDE is clearly doing what it is specified to do. However,
since 'c-set-style' may be called more than once when initializing a
buffer, the net effect of these semantics is to set variables which are
defined in the 'c-default-style' as well as in the 'c-file-style' to
their values in the 'c-default-style', which is surely wrong: the
'c-default-style' is a global fallback, and should not take precedence
over per-file or per-directory indentation styles.
We could fix all of this by not installing the default style at all if
'c-file-style' is set (whether in file-local or dir-local variables, we
do not care)... except that if c-file-style is set to a value which is
filtered out by the 'hack-local-variables-filter', we *do* want to
install the default style. And of course 'hack-local-variables' is not
always called (e.g. it is not if you just run 'c-mode') and in that
situation you presumably *do* want to set the style to the default. So
this seems excessively complex and fragile: we don't want code inside
c-mode to depend on the precise circumstances in which files.el chooses
to call 'hack-local-variables', nor do we want to end up with situations
in which c-mode starts up without setting an indentation style at all.
This tangle is most easily escaped by adding an extra valid value to
c-set-style's DONT-OVERRIDE, 'defaulting'. This is passed down when
defaulting the style if and only if 'c-old-style-variable-behavior' and
'c-indentation-style' are both nil, indicating that style variables
override the defaults and that we are not doing a subsequent style
switch in global style mode. 'c-set-style' (or, rather, 'c-set-style-1')
responds to this new value by adding the variable's name to a new list
'c-defaulted-style-variables' (buffer-local iff
'c-style-variables-are-local-p' is t); other calls to 'c-set-style' will
override this variable's value both if its value is 'set-from-style' (as
now) *and* if it is on the 'c-defaulted-style-variables' list. (There is
another, similar variable 'c-defaulted-style-offsets' to track defaulted
values within 'c-offsets-alist', because if the default style has set a
number of values in this list, we want to be able to reset some of them
in the file-local style, some in the dir-local style, and some in any
styles it may inherit from, but without permitting the inherited style
to override offset values in the the more-derived style. Currently, this
machinery is so broken that even ordinary inherited styles aren't
working: if you derive 'otbs' from 'bsd', the settings in 'bsd' override
the settings in 'otbs' rather than the other way around.)
The net effect of all this is that variables defined only in the default
style and not in the c-file-style or manually-applied style stick
around: other variables are immediately overwritten by their
c-file-style or manually-applied values. It seems to me that this is
precisely what is normally wanted.
(The only situation in which this might go wrong is if you enter a
buffer in the default style, change a style variable manually, then set
another style and pass in t for DONT-OVERRIDE. In this situation, the
'c-set-style' will take precedence, while in the current system the
style variable would. This is probably not a significant change: you're
not supposed to pass in a DONT-OVERRIDE of t yourself anyway.)
This is very confusing stuff (and the above is much too long for a log
message). The result seems to work, but could do with review: it may
well be that there is a way to do this that does not require two new
lists whose sole purpose is to filter the application of style
variables. (I thought that some clever reordering so that default styles
were somehow applied after any non-default ones might have worked until
I discovered that inherited styles were broken too.)
Certainly the state of play before this change works worse, but that's
about as confident as I'm willing to be.
2011-05-18 Nix <nix@esperi.org.uk>
* progmodes/cc-mode.el (c-basic-common-init): Pass in
'defaulting to `c-set-style' when setting up the
`c-default-style'.
* progmodes/cc-styles.el (c-style-defaulted-variables): New.
* progmodes/cc-styles.el (c-style-defaulted-offsets): New.
* progmodes/cc-styles.el (c-set-style-1): Use it to permit
otherwise-filtered offsets and variables to be set, not
* progmodes/cc-styles.el (c-set-style):
* progmodes/cc-styles.el (c-make-styles-buffer-local):
* progmodes/cc-styles.el (cc-styles):
=== modified file 'lisp/progmodes/cc-mode.el'
Index: lisp/progmodes/cc-mode.el
===================================================================
--- lisp/progmodes/cc-mode.el.orig 2011-05-17 16:01:50.000000000 +0100
+++ lisp/progmodes/cc-mode.el 2011-05-17 16:07:41.870198468 +0100
@@ -565,11 +565,12 @@
;; the whole situation with nonlocal style variables is a bit
;; awkward. It's at least the most compatible way with the old
;; style init procedure.)
- (c-set-style style (not (or c-old-style-variable-behavior
- (and (not c-style-variables-are-local-p)
- c-indentation-style
- (not (string-equal c-indentation-style
- style)))))))
+ (c-set-style style (if (not (or c-old-style-variable-behavior
+ (and (not c-style-variables-are-local-p)
+ c-indentation-style
+ (not (string-equal c-indentation-style
+ style)))))
+ 'defaulting)))
(c-setup-paragraph-variables)
;; we have to do something special for c-offsets-alist so that the
Index: lisp/progmodes/cc-styles.el
===================================================================
--- lisp/progmodes/cc-styles.el.orig 2011-05-17 16:01:50.000000000 +0100
+++ lisp/progmodes/cc-styles.el 2011-05-17 23:57:52.719539336 +0100
@@ -271,6 +271,21 @@
modify existing styles -- you should create a new style that inherits
the existing style).")
+(defvar c-style-defaulted-variables '()
+"A list of variables that have been defaulted by the application of a style.
+
+This list contains only those variables that have been set by the
+`c-default-style' but not subsequently overridden by a `c-set-style' call.
+
+`c-offsets-alist' is not represented in this list at all, but rather in
+`c-style-defaulted-offsets'.")
+
+(defvar c-style-defaulted-offsets '()
+"A list of offsets that have been defaulted by the application of a style.
+
+This list contains only those offsets that have been set by the
+`c-default-style' but not subsequently overridden by a `c-set-style' call.")
+
\f
;; Functions that manipulate styles
(defun c-set-style-1 (conscell dont-override)
@@ -284,11 +299,29 @@
c-offsets-alist)
(dont-override
(default-value 'c-offsets-alist)))))
+ ;; If values in the offsets list have been defaulted, don't screen them
+ ;; out, even under dont-override.
+ (if (and c-style-defaulted-offsets offsets)
+ (let (accum)
+ (mapc (lambda (offset)
+ (unless (memq (car offset) c-style-defaulted-offsets)
+ (setq accum (cons offset accum))))
+ offsets)
+ (setq offsets accum)))
+ ;; Set everything that isn't in the offsets list; remove such things from
+ ;; c-style-defaulted-offsets unless this is a defaulting run, in which case
+ ;; add them instead
(mapcar (lambda (langentry)
(let ((langelem (car langentry))
(offset (cdr langentry)))
(unless (assq langelem offsets)
- (c-set-offset langelem offset))))
+ (c-set-offset langelem offset)
+ (when (and (not (eq dont-override 'defaulting))
+ (memq langelem c-style-defaulted-offsets))
+ (setq c-style-defaulted-offsets (delq langelem c-style-defaulted-offsets))))
+ (when (and (eq dont-override 'defaulting)
+ (not (memq langelem c-style-defaulted-offsets)))
+ (setq c-style-defaulted-offsets (cons langelem c-style-defaulted-offsets)))))
val)))
;; second special variable
((eq attr 'c-special-indent-hook)
@@ -296,6 +329,8 @@
;; hooks?
(unless (cond ((eq dont-override t)
c-special-indent-hook)
+ ((memq 'c-special-indent-hook c-style-defaulted-variables)
+ nil)
(dont-override
(default-value 'c-special-indent-hook)))
(if (listp val)
@@ -306,6 +341,7 @@
;; all other variables
(t (when (or (not dont-override)
(not (memq attr c-style-variables))
+ (memq attr c-style-defaulted-variables)
(eq (if (eq dont-override t)
(symbol-value attr)
(default-value attr))
@@ -314,7 +350,15 @@
;; Must update a number of other variables if
;; c-comment-prefix-regexp is set.
(if (eq attr 'c-comment-prefix-regexp)
- (c-setup-paragraph-variables)))))))
+ (c-setup-paragraph-variables)))))
+
+ ;; If this is a run to set the default style, note that this variable can
+ ;; now be freely overwridden by later calls to this function. Otherwise,
+ ;; take it out again: it's been overridden, if it was there.
+ (if (and (eq dont-override 'defaulting)
+ (not (eq attr 'c-offsets-alist))) ; this is recorded elsewhere
+ (add-to-list 'c-style-defaulted-variables attr)
+ (setq c-style-defaulted-variables (remq attr c-style-defaulted-variables)))))
(defun c-get-style-variables (style basestyles)
;; Return all variables in a style by resolving inheritances.
@@ -351,7 +395,7 @@
If DONT-OVERRIDE is neither nil nor t, style variables whose default values
have been set (more precisely, whose default values are not the symbol
-`set-from-style') will not be changed. This avoids overriding global settings
+`set-from-style') will not be changed. This avoids overriding global settings
done in ~/.emacs. It is useful to call c-set-style from a mode hook in this
way.
@@ -359,7 +403,12 @@
values are not the symbol `set-from-style') will not be overridden. CC Mode
calls c-set-style internally in this way whilst initializing a buffer; if
cc-set-style is called like this from anywhere else, it will usually behave as
-a null operation."
+a null operation.
+
+If DONT-OVERRIDE is the symbol `defaulting', style variables are set in such
+a way that later calls to `c-set-style' will unconditionally override them
+again, even if called with DONT-OVERRIDE t. This is is used when setting
+style variables to the `c-default-style' early in initialization."
(interactive
(list (let ((completion-ignore-case t)
(prompt (format "Which %s indentation style? "
@@ -373,7 +422,8 @@
(error "Argument to c-set-style was not a string"))
(c-initialize-builtin-style)
(let ((vars (c-get-style-variables stylename nil)))
- (unless dont-override
+ (unless (and dont-override
+ (not (eq dont-override 'defaulting)))
;; Since we always add to c-special-indent-hook we must reset it
;; first, or else the hooks from the preceding style will
;; remain. This is not necessary for c-offsets-alist, since
@@ -640,15 +690,17 @@
(let ((func (if this-buf-only-p
'make-local-variable
'make-variable-buffer-local))
- (varsyms (cons 'c-indentation-style (copy-alist c-style-variables))))
+ (varsyms (append '(c-indentation-style
+ c-style-defaulted-variables
+ c-style-defaulted-offsets)
+ (copy-alist c-style-variables))))
(delq 'c-special-indent-hook varsyms)
(mapc func varsyms)
;; Hooks must be handled specially
(if this-buf-only-p
(if (featurep 'xemacs) (make-local-hook 'c-special-indent-hook))
(with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
- (setq c-style-variables-are-local-p t))
- ))
+ (setq c-style-variables-are-local-p t))))
\f
--
NULL && (void)
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation
2011-05-17 23:21 [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation Nix
@ 2011-05-18 0:17 ` Stefan Monnier
2011-05-18 20:28 ` Nix
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2011-05-18 0:17 UTC (permalink / raw)
To: Nix; +Cc: emacs-devel
> Certainly the state of play before this change works worse, but that's
> about as confident as I'm willing to be.
Thanks for taking the trouble to track down your problem and provide
a fix. I'll let Alan check the actual change and decide if it's
safe enough.
But I just want to take the opportunity to say that all this CC style
business is much too complex for its own sake, and as a result we've
seen and keep seeing new problems that require additional hacks on top
of hacks to try and "fix" things. I don't have the time/energy to
devote to cleaning this up, but it really needs a rethink and redesign
so that we can simplify the whole thing, thus removing warts rather than
working around them.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation
2011-05-18 0:17 ` Stefan Monnier
@ 2011-05-18 20:28 ` Nix
2011-05-18 21:08 ` ERT indentation testing (was: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation) Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Nix @ 2011-05-18 20:28 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On 18 May 2011, Stefan Monnier outgrape:
> But I just want to take the opportunity to say that all this CC style
> business is much too complex for its own sake, and as a result we've
> seen and keep seeing new problems that require additional hacks on top
> of hacks to try and "fix" things.
Gods, yes. Most of this appears to be the interaction of backward-
compatibility kludge atop backward-compatibility kludge.
The indentation engine works great (the most nearly flawless I've ever
seen), and the style engine needs a certain degree of complexity --
things like inherited styles are a must, because so many styles in the
real world are almost like one of cc-mode's except for a couple of tiny
differences.
But the support for configuration through global variables *or* styles,
with styles possibly taking effect by localizing variables in one buffer
or possibly taking effect by making them local to all buffers... well,
it's just ridiculous. Rip out all that stuff and use the recommended
configuration only (style variables automatically localized to the
current buffer, direct setting of style variables always overrides the
style itself via 'set-from-style) and ditch all the rest. I'm fairly
sure that half the configurations implied by the current set of
variables are broken at any one time, because there are so many that
nobody can really test them.
(That's an alternative: a decent testing framework for this stuff, such
that we could be sure it didn't break. Then it wouldn't matter so much
how complex it got, except insofar as it bends the brains of people
trying to look at the code.)
--
NULL && (void)
^ permalink raw reply [flat|nested] 15+ messages in thread
* ERT indentation testing (was: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation)
2011-05-18 20:28 ` Nix
@ 2011-05-18 21:08 ` Ted Zlatanov
2011-05-18 22:19 ` ERT indentation testing Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-05-18 21:08 UTC (permalink / raw)
To: emacs-devel
On Wed, 18 May 2011 21:28:34 +0100 Nix <nix@esperi.org.uk> wrote:
N> (That's an alternative: a decent testing framework for this stuff, such
N> that we could be sure it didn't break. Then it wouldn't matter so much
N> how complex it got, except insofar as it bends the brains of people
N> trying to look at the code.)
This can be done with ERT, right? A bunch of .cc files with file-local
variables could be indented "properly" for those variables. Then the
test logic for each file is
1) open file and evaluate file-local variables,
2) reindent and untabify the whole file,
3) compare the result to the untabified original file.
The nice thing about this approach is that all the test logic is inside
the .cc file, so you don't need to configure the ELisp code for each
file separately. To add a new test you just add a new .cc file.
Plus, of course, it's not limited to .cc files. It would work just as
well for .c, .pl, .el, whatever. I can write the ERT wrapper if this
sounds useful.
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-05-18 21:08 ` ERT indentation testing (was: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation) Ted Zlatanov
@ 2011-05-18 22:19 ` Stefan Monnier
2011-05-19 10:33 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2011-05-18 22:19 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: emacs-devel
> This can be done with ERT, right? A bunch of .cc files with file-local
> variables could be indented "properly" for those variables. Then the
> test logic for each file is
[...]
> Plus, of course, it's not limited to .cc files. It would work just as
> well for .c, .pl, .el, whatever.
Yup, we already have such files in test/indent.
> I can write the ERT wrapper if this sounds useful.
If you could integrate test/indent with ERT's automated tests, that
would be nice.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-05-18 22:19 ` ERT indentation testing Stefan Monnier
@ 2011-05-19 10:33 ` Ted Zlatanov
2011-05-19 11:56 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-05-19 10:33 UTC (permalink / raw)
To: emacs-devel
On Wed, 18 May 2011 19:19:25 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> This can be done with ERT, right? A bunch of .cc files with file-local
>> variables could be indented "properly" for those variables. Then the
>> test logic for each file is
SM> [...]
>> Plus, of course, it's not limited to .cc files. It would work just as
>> well for .c, .pl, .el, whatever.
SM> Yup, we already have such files in test/indent.
Yes, I see that now (I didn't see the commit for those, cool!)
We should have .c and .cc files with the major indentation styles
specified as file-local variables, plus .ini, Perl, Java, Python, and of
course Lisp (CL and ELisp). Should I add those?
>> I can write the ERT wrapper if this sounds useful.
SM> If you could integrate test/indent with ERT's automated tests, that
SM> would be nice.
OK, I'll put it on my TODO list.
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-05-19 10:33 ` Ted Zlatanov
@ 2011-05-19 11:56 ` Stefan Monnier
2011-06-01 21:30 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2011-05-19 11:56 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: emacs-devel
>>> This can be done with ERT, right? A bunch of .cc files with file-local
>>> variables could be indented "properly" for those variables. Then the
>>> test logic for each file is
SM> [...]
>>> Plus, of course, it's not limited to .cc files. It would work just as
>>> well for .c, .pl, .el, whatever.
SM> Yup, we already have such files in test/indent.
> Yes, I see that now (I didn't see the commit for those, cool!)
> We should have .c and .cc files with the major indentation styles
> specified as file-local variables, plus .ini, Perl, Java, Python, and of
> course Lisp (CL and ELisp). Should I add those?
Feel free. I only added the ones I actually worked on. BTW, the
octave.m testcase is too long for that kind of test (although the length
was instrumental in fixing some performance bugs).
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-05-19 11:56 ` Stefan Monnier
@ 2011-06-01 21:30 ` Ted Zlatanov
2011-06-02 18:43 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-01 21:30 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]
On Thu, 19 May 2011 08:56:07 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>>> This can be done with ERT, right? A bunch of .cc files with file-local
>>>> variables could be indented "properly" for those variables. Then the
>>>> test logic for each file is
SM> [...]
>>>> Plus, of course, it's not limited to .cc files. It would work just as
>>>> well for .c, .pl, .el, whatever.
SM> Yup, we already have such files in test/indent.
>> Yes, I see that now (I didn't see the commit for those, cool!)
>> We should have .c and .cc files with the major indentation styles
>> specified as file-local variables, plus .ini, Perl, Java, Python, and of
>> course Lisp (CL and ELisp). Should I add those?
SM> Feel free. I only added the ones I actually worked on. BTW, the
SM> octave.m testcase is too long for that kind of test (although the length
SM> was instrumental in fixing some performance bugs).
See the attached patch to make the indentation testing use ERT and
operate on any files with a "." in the name except test-indent.el.
The test fails on modula2.mod and I'm not sure why. I am setting
`enable-local-variables'. Is it because I'm going line by line? Or
something with the line boundaries?
Should the test stop when any file fails or keep going?
Thanks
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test-indent.patch --]
[-- Type: text/x-diff, Size: 2729 bytes --]
=== modified file 'test/indent/Makefile'
--- test/indent/Makefile 2010-08-30 20:34:52 +0000
+++ test/indent/Makefile 2011-06-01 20:48:21 +0000
@@ -13,3 +13,6 @@
--eval '(indent-region (point-min) (point-max) nil)' \
--eval '(write-region (point-min) (point-max) "$<.new")'
diff -u -B $< $<.new
+
+test-indent:
+ $(EMACS) --batch -l ert -l test-indent.el -f ert-run-tests-batch-and-exit
=== added file 'test/indent/test-indent.el'
--- test/indent/test-indent.el 1970-01-01 00:00:00 +0000
+++ test/indent/test-indent.el 2011-06-01 21:28:07 +0000
@@ -0,0 +1,57 @@
+;;; test-indent.el --- run indentation tests
+
+;; Copyright (C) 2011 Free Software Foundation, Inc.
+
+;; Author: Ted Zlatanov <tzz@lifelogs.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The purpose of this module is to verify that all the files in te
+;; current directory are indented correctly.
+
+;;; Code:
+
+(eval-when-compile
+ (require 'ert)
+ (require 'cl))
+
+(ert-deftest test-indent-all ()
+ (let ((enable-local-variables :all)
+ lnum)
+ (loop for f in (delete "test-indent.el"
+ (directory-files "." nil "^[^.]+\\."))
+ do (with-temp-buffer
+ (message "Testing indentation of %s" f)
+ (insert-file-contents f)
+ (goto-char (point-min))
+ (setq lnum 0)
+ (while (not (eobp))
+ (incf lnum)
+ (let* ((a (line-beginning-position))
+ (b (line-end-position))
+ (line (buffer-substring a b)))
+ (message "Testing indentation of %s:%05d: %s" f lnum line)
+ (unless (string-match "KNOWN INDENT BUG" line)
+ (indent-region a b nil)
+ (should (equal line (buffer-substring
+ (line-beginning-position)
+ (line-end-position)))))
+ (forward-line)))))))
+
+(provide 'test-indent)
+;;; test-indent.el ends here
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-01 21:30 ` Ted Zlatanov
@ 2011-06-02 18:43 ` Ted Zlatanov
2011-06-03 0:04 ` Stefan Monnier
2011-06-08 10:44 ` Ted Zlatanov
0 siblings, 2 replies; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-02 18:43 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 625 bytes --]
On Wed, 01 Jun 2011 16:30:56 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> See the attached patch to make the indentation testing use ERT and
TZ> operate on any files with a "." in the name except test-indent.el.
Second patch:
TZ> The test fails on modula2.mod and I'm not sure why. I am setting
TZ> `enable-local-variables'. Is it because I'm going line by line? Or
TZ> something with the line boundaries?
Uses `find-file' to process the local variables correctly.
TZ> Should the test stop when any file fails or keep going?
One test is created per file now, and any one file won't block the other tests.
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test-indent.patch --]
[-- Type: text/x-diff, Size: 3376 bytes --]
=== modified file 'test/indent/Makefile'
--- test/indent/Makefile 2010-08-30 20:34:52 +0000
+++ test/indent/Makefile 2011-06-02 18:07:15 +0000
@@ -13,3 +13,6 @@
--eval '(indent-region (point-min) (point-max) nil)' \
--eval '(write-region (point-min) (point-max) "$<.new")'
diff -u -B $< $<.new
+
+test-indent:
+ $(EMACS) --batch -l ert -l test-indent.el -f ert-run-tests-batch-and-exit
=== added file 'test/indent/test-indent.el'
--- test/indent/test-indent.el 1970-01-01 00:00:00 +0000
+++ test/indent/test-indent.el 2011-06-02 18:39:23 +0000
@@ -0,0 +1,67 @@
+;;; test-indent.el --- run indentation tests
+
+;; Copyright (C) 2011 Free Software Foundation, Inc.
+
+;; Author: Ted Zlatanov <tzz@lifelogs.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The purpose of this module is to verify that all the files in te
+;; current directory are indented correctly.
+
+;;; Code:
+
+(eval-when-compile
+ (require 'ert)
+ (require 'cl)
+
+ (defsubst test-indent-trim (string)
+ "Lose leading and trailing whitespace. Copied from BBDB."
+ (if (string-match "\\`[ \t\n]+" string)
+ (setq string (substring string (match-end 0))))
+ (if (string-match "[ \t\n]+\\'" string)
+ (setq string (substring string 0 (match-beginning 0))))
+ string)
+
+ (let ((files (delete "test-indent.el"
+ (directory-files "." nil "\\`[^.]+\\..+[a-zA-Z]\\'")))
+ f)
+ (loop for i from 1 to (length files)
+ for f = (nth (1- i) files)
+ do (eval `(ert-deftest ,(intern (format "test-indent-%d-%s" i f)) ()
+ (let ((lnum 0))
+ (message "Testing indentation of %s" ,f)
+ (find-file ,f)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (incf lnum)
+ (let* ((a (line-beginning-position))
+ (b (line-end-position))
+ (line (buffer-substring a b)))
+ (message "Testing indentation of %s:%05d: %s"
+ ,f lnum line)
+ (unless (or (string-match "KNOWN INDENT BUG" line)
+ (equal (test-indent-trim line) ""))
+ (indent-region a b nil)
+ (should (equal line (buffer-substring
+ (line-beginning-position)
+ (line-end-position)))))
+ (forward-line)))))))))
+
+(provide 'test-indent)
+;;; test-indent.el ends here
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-02 18:43 ` Ted Zlatanov
@ 2011-06-03 0:04 ` Stefan Monnier
2011-06-03 11:33 ` Ted Zlatanov
2011-06-08 10:44 ` Ted Zlatanov
1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2011-06-03 0:04 UTC (permalink / raw)
To: emacs-devel
> Uses `find-file' to process the local variables correctly.
Never call `find-file' from Elisp. Always call
find-file-noselect instead.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-03 0:04 ` Stefan Monnier
@ 2011-06-03 11:33 ` Ted Zlatanov
2011-06-03 12:12 ` martin rudalics
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-03 11:33 UTC (permalink / raw)
To: emacs-devel
On Thu, 02 Jun 2011 21:04:59 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Uses `find-file' to process the local variables correctly.
SM> Never call `find-file' from Elisp. Always call
SM> find-file-noselect instead.
I was trying to copy your original test, which I think uses `find-file':
#+begin_src makefile
%.test: %
-$(RM) $<.new
$(EMACS) --batch $< \
--eval '(indent-region (point-min) (point-max) nil)' \
--eval '(write-region (point-min) (point-max) "$<.new")'
diff -u -B $< $<.new
#+end_src
Using `find-file-noselect' will just make me select the buffer in ELisp
instead of expecting it to become current. Is there any real reason to
avoid `find-file'? Because of the prompts? I ask because I'm curious;
I've already changed my patch to use (set-buffer (find-file-noselect...))
but can't commit because the Bazaar repo is down.
Also, if `find-file' should be avoided in ELisp generally, the docstring
should say so, like it does for many other functions.
Actually it might be nice if there was a standard way to tag such
extra-interactive functions that are not supposed to be called from an
ELisp context, only from `M-x' or through a key. A symbol property
maybe? Then the compiler could check it and print suitable errors...
Tell me it already exists :)
Thanks
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-03 11:33 ` Ted Zlatanov
@ 2011-06-03 12:12 ` martin rudalics
0 siblings, 0 replies; 15+ messages in thread
From: martin rudalics @ 2011-06-03 12:12 UTC (permalink / raw)
To: emacs-devel
> Using `find-file-noselect' will just make me select the buffer in ELisp
> instead of expecting it to become current. Is there any real reason to
> avoid `find-file'? Because of the prompts? I ask because I'm curious;
> I've already changed my patch to use (set-buffer (find-file-noselect...))
> but can't commit because the Bazaar repo is down.
`find-file' uses `switch-to-buffer' and `switch-to-buffer' should be
avoided in Elisp code.
> Also, if `find-file' should be avoided in ELisp generally, the docstring
> should say so, like it does for many other functions.
Indeed.
martin
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-02 18:43 ` Ted Zlatanov
2011-06-03 0:04 ` Stefan Monnier
@ 2011-06-08 10:44 ` Ted Zlatanov
2011-06-08 15:24 ` Stefan Monnier
1 sibling, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-08 10:44 UTC (permalink / raw)
To: emacs-devel
On Thu, 02 Jun 2011 13:43:27 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> On Wed, 01 Jun 2011 16:30:56 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> See the attached patch to make the indentation testing use ERT and
TZ> operate on any files with a "." in the name except test-indent.el.
TZ> Second patch:
TZ> The test fails on modula2.mod and I'm not sure why. I am setting
TZ> `enable-local-variables'. Is it because I'm going line by line? Or
TZ> something with the line boundaries?
TZ> Uses `find-file' to process the local variables correctly.
Is the patch above usable (using `find-file-noselect' as discussed)?
Should I keep working on this, commit it as is, or forget about it?
Thanks
Ted
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-08 10:44 ` Ted Zlatanov
@ 2011-06-08 15:24 ` Stefan Monnier
2011-06-09 16:05 ` Ted Zlatanov
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2011-06-08 15:24 UTC (permalink / raw)
To: emacs-devel
> Is the patch above usable (using `find-file-noselect' as discussed)?
I trust your judgment on it. The functionality is one I'd like to see,
but I don't have time to check the actual code.
> Should I keep working on this, commit it as is, or forget about it?
If/when you think it's ready, please install it.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-08 15:24 ` Stefan Monnier
@ 2011-06-09 16:05 ` Ted Zlatanov
2011-06-10 20:41 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2011-06-09 16:05 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 830 bytes --]
On Wed, 08 Jun 2011 12:24:13 -0300 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Is the patch above usable (using `find-file-noselect' as discussed)?
SM> I trust your judgment on it. The functionality is one I'd like to see,
SM> but I don't have time to check the actual code.
OK, great.
>> Should I keep working on this, commit it as is, or forget about it?
SM> If/when you think it's ready, please install it.
I'm concerned that it's failing a few tests. I think the files are
incorrect for the .rc and .sh content, don't know about the Prolog.
FAILED test-indent-2-prolog\.prolog
FAILED test-indent-3-shell\.rc
FAILED test-indent-4-shell\.sh
Third patch attached, just "make test-indent". If you think those tests
are legitimate failures, I'll commit, but otherwise I should fix them.
Thanks
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test-indent.patch --]
[-- Type: text/x-diff, Size: 3398 bytes --]
=== modified file 'test/indent/Makefile'
--- test/indent/Makefile 2010-08-30 20:34:52 +0000
+++ test/indent/Makefile 2011-06-02 18:07:15 +0000
@@ -13,3 +13,6 @@
--eval '(indent-region (point-min) (point-max) nil)' \
--eval '(write-region (point-min) (point-max) "$<.new")'
diff -u -B $< $<.new
+
+test-indent:
+ $(EMACS) --batch -l ert -l test-indent.el -f ert-run-tests-batch-and-exit
=== added file 'test/indent/test-indent.el'
--- test/indent/test-indent.el 1970-01-01 00:00:00 +0000
+++ test/indent/test-indent.el 2011-06-02 18:39:23 +0000
@@ -0,0 +1,67 @@
+;;; test-indent.el --- run indentation tests
+
+;; Copyright (C) 2011 Free Software Foundation, Inc.
+
+;; Author: Ted Zlatanov <tzz@lifelogs.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The purpose of this module is to verify that all the files in te
+;; current directory are indented correctly.
+
+;;; Code:
+
+(eval-when-compile
+ (require 'ert)
+ (require 'cl)
+
+ (defsubst test-indent-trim (string)
+ "Lose leading and trailing whitespace. Copied from BBDB."
+ (if (string-match "\\`[ \t\n]+" string)
+ (setq string (substring string (match-end 0))))
+ (if (string-match "[ \t\n]+\\'" string)
+ (setq string (substring string 0 (match-beginning 0))))
+ string)
+
+ (let ((files (delete "test-indent.el"
+ (directory-files "." nil "\\`[^.]+\\..+[a-zA-Z]\\'")))
+ f)
+ (loop for i from 1 to (length files)
+ for f = (nth (1- i) files)
+ do (eval `(ert-deftest ,(intern (format "test-indent-%d-%s" i f)) ()
+ (let ((lnum 0))
+ (message "Testing indentation of %s" ,f)
+ (set-buffer (find-file-noselect ,f))
+ (goto-char (point-min))
+ (while (not (eobp))
+ (incf lnum)
+ (let* ((a (line-beginning-position))
+ (b (line-end-position))
+ (line (buffer-substring a b)))
+ (message "Testing indentation of %s:%05d: %s"
+ ,f lnum line)
+ (unless (or (string-match "KNOWN INDENT BUG" line)
+ (equal (test-indent-trim line) ""))
+ (indent-region a b nil)
+ (should (equal line (buffer-substring
+ (line-beginning-position)
+ (line-end-position)))))
+ (forward-line)))))))))
+
+(provide 'test-indent)
+;;; test-indent.el ends here
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: ERT indentation testing
2011-06-09 16:05 ` Ted Zlatanov
@ 2011-06-10 20:41 ` Stefan Monnier
0 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2011-06-10 20:41 UTC (permalink / raw)
To: emacs-devel
> I'm concerned that it's failing a few tests. I think the files are
> incorrect for the .rc and .sh content, don't know about the Prolog.
> FAILED test-indent-2-prolog\.prolog
> FAILED test-indent-3-shell\.rc
> FAILED test-indent-4-shell\.sh
Check the current result of the test in test/indent.
If the same problems show up there, it's a sign those have nothing to do
with your changes,
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2011-06-10 20:41 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-02 12:37 ERT indentation testing Alan Mackenzie
2011-06-02 14:23 ` Ted Zlatanov
2011-06-03 11:48 ` Ted Zlatanov
-- strict thread matches above, loose matches on Subject: below --
2011-05-17 23:21 [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation Nix
2011-05-18 0:17 ` Stefan Monnier
2011-05-18 20:28 ` Nix
2011-05-18 21:08 ` ERT indentation testing (was: [RFC PATCH] setting indentation styles via `c-file-style' fails to actually change indentation) Ted Zlatanov
2011-05-18 22:19 ` ERT indentation testing Stefan Monnier
2011-05-19 10:33 ` Ted Zlatanov
2011-05-19 11:56 ` Stefan Monnier
2011-06-01 21:30 ` Ted Zlatanov
2011-06-02 18:43 ` Ted Zlatanov
2011-06-03 0:04 ` Stefan Monnier
2011-06-03 11:33 ` Ted Zlatanov
2011-06-03 12:12 ` martin rudalics
2011-06-08 10:44 ` Ted Zlatanov
2011-06-08 15:24 ` Stefan Monnier
2011-06-09 16:05 ` Ted Zlatanov
2011-06-10 20:41 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.