unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Testing font things
@ 2022-11-21 13:42 Stefan Monnier
  2022-11-21 14:12 ` Eli Zaretskii
  2022-11-22  0:24 ` Po Lu
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-11-21 13:42 UTC (permalink / raw)
  To: emacs-devel

I'm trying to write a test for our font choice code (bug#59347)
Here's the situation so far:

- I have not been able to create a GUI frame from a `--batch` process :-(
  The process gets killed by SIGIO.  I tried to change
  `(un)request_sigio` so as to ignore `noninteractive` but without
  any success.

- So I resorted to an `--fg-daemon` (with the patch below to let me
  start a daemon without creating the server socket and waiting for
  connections).

- With this, I'm able to get pretty much what I want with:

      src/emacs -Q --fg-daemon=none -l test/src/font-tests.el \
                 -f ert-run-tests-batch

  The code in font-tests.el looks like:

      (defvar font-tests--gui-frame
        (unless noninteractive ;; I get "killed by SIGIO" in batch mode :-(
          (with-demoted-errors "%S"
            (make-frame-on-display
             (getenv "DISPLAY")
             '((visibility . nil)
               ;; Tell the window manager not to ask the user to
               ;; manually place the frame/window.
               (user-position . t)
               (left . 0)
               (top . 0)
               (no-other-frame . t))))))
      
      (defvar font-tests--dejavu-sans
        (when font-tests--gui-frame
          (list-fonts (font-spec :family "DejaVu Sans")
                      font-tests--gui-frame)))
      
      (defvar font-tests--misc-fixed
        (when font-tests--gui-frame
          (list-fonts
           (font-spec :name "-misc-fixed-*-*-semicondensed-*-13-*-*-*-*-*-*-*")
           font-tests--gui-frame)))
      
      (ert-deftest font-tests--bug59347 ()
        (skip-unless (and font-tests--misc-fixed font-tests--dejavu-sans))
        (face-spec-set
         'default
         '((t :font "-misc-fixed-*-*-semicondensed-*-13-*-*-*-*-*-*-*")))
        (face-spec-set 'font-tests-dejavu '((t :family "DejaVu Sans")))
        (with-temp-buffer
          (let ((w (frame-root-window font-tests--gui-frame)))
            (set-window-buffer w (current-buffer))
            (insert "hello " (propertize "world" 'face 'font-tests-dejavu))
            (should (member (font-at (1+ (point-min)) w)
                            font-tests--misc-fixed))
            (should (member (font-at (1- (point-max)) w)
                            font-tests--dejavu-sans)))))

  But this fails because `fonts-at` gets me a "font-object" whereas
  `list-fonts` gets me "font entities".  How can I convert one to
  the other?


-- Stefan




diff --git a/lisp/startup.el b/lisp/startup.el
index 5e0a47d3f8f..7dc35e2392c 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -390,7 +390,7 @@ user-mail-address
   "The email address of the current user.
 This defaults to either: the value of EMAIL environment variable; or
 user@host, using `user-login-name' and `mail-host-address' (or `system-name')."
-  :initialize 'custom-initialize-delay
+  :initialize #'custom-initialize-delay
   :set-after '(mail-host-address)
   :type 'string
   :group 'mail)
@@ -1613,7 +1613,11 @@ command-line
   ;; processing all command line arguments to allow e.g. `server-name'
   ;; to be changed before the server starts.
   (let ((dn (daemonp)))
-    (when dn
+    (cond
+     ((equal dn "none")
+      (message "Not starting any server; exiting")
+      (kill-emacs 1))
+     (dn
       (when (stringp dn) (setq server-name dn))
       (server-start)
       (if server-process
@@ -1623,7 +1627,7 @@ command-line
 	     "Unable to start daemon: Emacs server named %S already running"
 	     server-name)
 	  (message "Unable to start the daemon.\nAnother instance of Emacs is running the server, either as daemon or interactively.\nYou can use emacsclient to connect to that Emacs process."))
-	(kill-emacs 1))))
+	(kill-emacs 1)))))
 
   ;; Run emacs-session-restore (session management) if started by
   ;; the session manager and we have a session manager connection.




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-21 13:42 Testing font things Stefan Monnier
@ 2022-11-21 14:12 ` Eli Zaretskii
  2022-11-30  3:31   ` Stefan Monnier
  2022-11-22  0:24 ` Po Lu
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2022-11-21 14:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Mon, 21 Nov 2022 08:42:01 -0500
> 
> I'm trying to write a test for our font choice code (bug#59347)

Is it useful?  This test will work only on your platform and maybe on a few
other lucky ones.  The list of fonts installed on any given system is
unpredictable.

I suggest to defer coding of the test until we fully understand the problem,
and then try to write the test in some generic way independent of specific
font families.

That said...

>       (ert-deftest font-tests--bug59347 ()
>         (skip-unless (and font-tests--misc-fixed font-tests--dejavu-sans))
>         (face-spec-set
>          'default
>          '((t :font "-misc-fixed-*-*-semicondensed-*-13-*-*-*-*-*-*-*")))
>         (face-spec-set 'font-tests-dejavu '((t :family "DejaVu Sans")))
>         (with-temp-buffer
>           (let ((w (frame-root-window font-tests--gui-frame)))
>             (set-window-buffer w (current-buffer))
>             (insert "hello " (propertize "world" 'face 'font-tests-dejavu))
>             (should (member (font-at (1+ (point-min)) w)
>                             font-tests--misc-fixed))
>             (should (member (font-at (1- (point-max)) w)
>                             font-tests--dejavu-sans)))))
> 
>   But this fails because `fonts-at` gets me a "font-object" whereas
>   `list-fonts` gets me "font entities".  How can I convert one to
>   the other?

...why do you need to go to these obscure entities, when you have the font's
name as a string to begin with?  So you should be able to:

  . use face-font, which returns the font's name as a string
  . compare that string with what you wanted it to be
  . and/or use find-font to check whether the font is in fact installed on
    the system

If the above is not enough, what is missing?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-21 13:42 Testing font things Stefan Monnier
  2022-11-21 14:12 ` Eli Zaretskii
@ 2022-11-22  0:24 ` Po Lu
  2022-11-30  3:48   ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Po Lu @ 2022-11-22  0:24 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>   The code in font-tests.el looks like:
>
>       (defvar font-tests--gui-frame
>         (unless noninteractive ;; I get "killed by SIGIO" in batch mode :-(
>           (with-demoted-errors "%S"
>             (make-frame-on-display
>              (getenv "DISPLAY")
>              '((visibility . nil)
>                ;; Tell the window manager not to ask the user to
>                ;; manually place the frame/window.
>                (user-position . t)
>                (left . 0)
>                (top . 0)
>                (no-other-frame . t))))))
>       
>       (defvar font-tests--dejavu-sans
>         (when font-tests--gui-frame
>           (list-fonts (font-spec :family "DejaVu Sans")
>                       font-tests--gui-frame)))
>       
>       (defvar font-tests--misc-fixed
>         (when font-tests--gui-frame
>           (list-fonts
>            (font-spec :name "-misc-fixed-*-*-semicondensed-*-13-*-*-*-*-*-*-*")
>            font-tests--gui-frame)))
>       
>       (ert-deftest font-tests--bug59347 ()
>         (skip-unless (and font-tests--misc-fixed font-tests--dejavu-sans))
>         (face-spec-set
>          'default
>          '((t :font "-misc-fixed-*-*-semicondensed-*-13-*-*-*-*-*-*-*")))
>         (face-spec-set 'font-tests-dejavu '((t :family "DejaVu Sans")))
>         (with-temp-buffer
>           (let ((w (frame-root-window font-tests--gui-frame)))
>             (set-window-buffer w (current-buffer))
>             (insert "hello " (propertize "world" 'face 'font-tests-dejavu))
>             (should (member (font-at (1+ (point-min)) w)
>                             font-tests--misc-fixed))
>             (should (member (font-at (1- (point-max)) w)
>                             font-tests--dejavu-sans)))))
>
>   But this fails because `fonts-at` gets me a "font-object" whereas
>   `list-fonts` gets me "font entities".  How can I convert one to
>   the other?

You should resort to comparing font attributes with `font-get' instead.
I don't think what you want is reliably possible.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-21 14:12 ` Eli Zaretskii
@ 2022-11-30  3:31   ` Stefan Monnier
  2022-11-30  5:06     ` Stefan Kangas
  2022-11-30 13:36     ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-11-30  3:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>> I'm trying to write a test for our font choice code (bug#59347)
> Is it useful?

We've had a fair bit of regressions in our font-selection code over the
years, and some of those have happened several times, so I think it
would be useful, yes.

> This test will work only on your platform and maybe on a few
> other lucky ones.

Sounds like a good reason to add more tests to cover other cases.
[ FWIW, Dejavu Sans is very widespread under GNU/Linux, AFAIK, and
  misc-fixed used to be very widespread as well, so there's a chance
  I'm not the only one where this test can run.  ]

> I suggest to defer coding of the test until we fully understand the
> problem, and then try to write the test in some generic way
> independent of specific font families.

Writing tests for the font code is not super easy, so I'd rather we get
started earlier than wait for some hypothetical future.  It's much
easier to improve/extend existing tests than trying to figure out how
the hell can we test GUI code in batch mode.

> ...why do you need to go to these obscure entities, when you have the font's
> name as a string to begin with?  So you should be able to:
>
>   . use face-font, which returns the font's name as a string

I'm not sure `face-font` will faithfully reproduce the result I'll see
on my screen.

>   . compare that string with what you wanted it to be

I'd rather not hard code any specific font name, actually, which is why
my code was written to just check that we get one of the available fonts
from the "DejaVu Sans" family.

>   . and/or use find-font to check whether the font is in fact installed on
>     the system

How does that compare to `list-fonts`?


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-22  0:24 ` Po Lu
@ 2022-11-30  3:48   ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-11-30  3:48 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

>>   But this fails because `fonts-at` gets me a "font-object" whereas
>>   `list-fonts` gets me "font entities".  How can I convert one to
>>   the other?
>
> You should resort to comparing font attributes with `font-get' instead.

I think I can get something acceptable with `font-get`. indeed,
thank you.

> I don't think what you want is reliably possible.

Hmmm... based on my naive understanding of these things I think we
should be able to convert a font-entity into a font-object by calling
the `open_font` method of the font driver.  Of course, this can fail and
it's not free so it's not a good option.

Similarly it should be possible to compare font-object and font-entities
but ignoring the last few fields.  Or offer a function to convert
a font-object or font-entity into a font-spec (similarly by dropping
the last few fields).

Also maybe we can use the FONT_OBJLIST_INDEX field of font-entities to
provide a "font-instance-of" test to see if a font-object is an instance
of a given font-entity.


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-30  3:31   ` Stefan Monnier
@ 2022-11-30  5:06     ` Stefan Kangas
  2022-11-30 13:36     ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Kangas @ 2022-11-30  5:06 UTC (permalink / raw)
  To: Stefan Monnier, Eli Zaretskii; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> [ FWIW, Dejavu Sans is very widespread under GNU/Linux, AFAIK,

Not just on GNU/Linux, according to Wikipedia:

    "Some operating systems (OpenBSD, Solaris, Haiku, AmigaOS 4, Linux
    distributions such as Ubuntu, Debian, Fedora, and RHEL) include
    DejaVu fonts in their default installation,[3][4][5][6][7] sometimes
    even using them as their system fonts."

https://en.wikipedia.org/wiki/DejaVu_fonts



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Testing font things
  2022-11-30  3:31   ` Stefan Monnier
  2022-11-30  5:06     ` Stefan Kangas
@ 2022-11-30 13:36     ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2022-11-30 13:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: emacs-devel@gnu.org
> Date: Tue, 29 Nov 2022 22:31:26 -0500
> 
> >> I'm trying to write a test for our font choice code (bug#59347)
> > Is it useful?
> 
> We've had a fair bit of regressions in our font-selection code over the
> years, and some of those have happened several times, so I think it
> would be useful, yes.

I was asking whether the particular approach you've chosen to implement such
tests was useful.  Not whether having tests about font selection in general
would be useful (which has a trivial answer).

> > This test will work only on your platform and maybe on a few
> > other lucky ones.
> 
> Sounds like a good reason to add more tests to cover other cases.

Not if all of them will have the same disadvantage.

> [ FWIW, Dejavu Sans is very widespread under GNU/Linux, AFAIK, and
>   misc-fixed used to be very widespread as well, so there's a chance
>   I'm not the only one where this test can run.  ]

A useful test should be runnable by more than just a handful.  From where I
stand, any test that I cannot run on my system is useless as a test.

> > I suggest to defer coding of the test until we fully understand the
> > problem, and then try to write the test in some generic way
> > independent of specific font families.
> 
> Writing tests for the font code is not super easy, so I'd rather we get
> started earlier than wait for some hypothetical future.  It's much
> easier to improve/extend existing tests than trying to figure out how
> the hell can we test GUI code in batch mode.

My point is that without understanding that problem fully, we don't know
what should be the expected results of a correctly-working Emacs.

> > ...why do you need to go to these obscure entities, when you have the font's
> > name as a string to begin with?  So you should be able to:
> >
> >   . use face-font, which returns the font's name as a string
> 
> I'm not sure `face-font` will faithfully reproduce the result I'll see
> on my screen.
> 
> >   . compare that string with what you wanted it to be
> 
> I'd rather not hard code any specific font name, actually, which is why
> my code was written to just check that we get one of the available fonts
> from the "DejaVu Sans" family.
> 
> >   . and/or use find-font to check whether the font is in fact installed on
> >     the system
> 
> How does that compare to `list-fonts`?

It avoids the problems you said got in your way.

Anyway, you asked for help in overcoming practical difficulties, and I tried
to do my best to help.  If my suggestions aren't useful, feel free to ignore
them (but know that I did base them on running and well-tested code which
needed to overcome similar obstacles while I was writing it).



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-30 13:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 13:42 Testing font things Stefan Monnier
2022-11-21 14:12 ` Eli Zaretskii
2022-11-30  3:31   ` Stefan Monnier
2022-11-30  5:06     ` Stefan Kangas
2022-11-30 13:36     ` Eli Zaretskii
2022-11-22  0:24 ` Po Lu
2022-11-30  3:48   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).