Browse Source

Make sure libmpdel-test validates package-lint

tags/v0.7.0
Damien Cassou 1 year ago
parent
commit
e844f80b37
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
1 changed files with 46 additions and 42 deletions
  1. +46
    -42
      test/libmpdel-test.el

+ 46
- 42
test/libmpdel-test.el View File

@@ -3,6 +3,9 @@
;; Copyright (C) 2017 Damien Cassou

;; Author: Damien Cassou <damien@cassou.me>
;; Url: https://gitlab.petton.fr/mpdel/mpdel
;; Package-requires: ((emacs "25.1"))
;; Version: 0.6.0

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -19,7 +22,7 @@

;;; Commentary:

;;
;; Tests for libmpdel.el.

;;; Code:

@@ -33,13 +36,13 @@
;;; Global private variables

(ert-deftest libmpel-response-regexp ()
(ert-deftest libmpdel-test--response-regexp ()
(should (string-match-p libmpdel--response-regexp "OK\n"))
(should (string-match-p libmpdel--response-regexp "OK MPD 0.20.0\n"))
(should (string-match-p libmpdel--response-regexp "ACK [51@10] {} unknown command \"foobar\"\n"))
(should (string-match-p libmpdel--response-regexp "Artist: A-ha\nOK\n")))

(ert-deftest libmpdel--msgfield-regexp ()
(ert-deftest libmpdel-test-msgfield-regexp ()
(save-match-data
(let ((line "key: value\n"))
(should (string-match libmpdel--msgfield-regexp line))
@@ -49,7 +52,7 @@
;;; Data structures

(ert-deftest libmpdel-artist ()
(ert-deftest libmpdel-test-artist ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album)))
@@ -57,7 +60,7 @@
(should (equal artist (libmpdel-artist album)))
(should (equal artist (libmpdel-artist song)))))

(ert-deftest libmpdel-artist-name ()
(ert-deftest libmpdel-test-artist-name ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album)))
@@ -65,7 +68,7 @@
(should (equal "The Artist" (libmpdel-artist-name album)))
(should (equal "The Artist" (libmpdel-artist-name song)))))

(ert-deftest libmpdel-album-name ()
(ert-deftest libmpdel-test-album-name ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album)))
@@ -73,7 +76,7 @@
(should (equal "The Album" (libmpdel-album-name album)))
(should (equal "The Album" (libmpdel-album-name song)))))

(ert-deftest libmpdel-album ()
(ert-deftest libmpdel-test-album ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album)))
@@ -81,7 +84,7 @@
(should (equal album (libmpdel-album album)))
(should (equal album (libmpdel-album song)))))

(ert-deftest libmpdel-entity-name ()
(ert-deftest libmpdel-test-entity-name ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album))
@@ -91,7 +94,7 @@
(should (equal "The song" (libmpdel-entity-name song)))
(should (equal "The playlist" (libmpdel-entity-name stored-playlist)))))

(ert-deftest libmpdel-entity-parent ()
(ert-deftest libmpdel-test-entity-parent ()
(let* ((artist (libmpdel--artist-create :name "The Artist"))
(album (libmpdel--album-create :name "The Album" :artist artist))
(song (libmpdel--song-create :name "The song" :album album))
@@ -104,7 +107,7 @@
(should-not (libmpdel-entity-parent 'artists))
(should-not (libmpdel-entity-parent 'current-playlist))))

(ert-deftest libmpdel-create-song-from-data ()
(ert-deftest libmpdel-test-create-song-from-data ()
(let ((song (libmpdel--create-song-from-data
'((Title . "The song")
(file . "foo/song.ogg")
@@ -115,7 +118,7 @@
(should (equal "The Album" (libmpdel-entity-name (libmpdel-album song))))
(should (equal "The Artist" (libmpdel-entity-name (libmpdel-artist (libmpdel-album song)))))))

(ert-deftest libmpdel-current-playlist-p ()
(ert-deftest libmpdel-test-current-playlist-p ()
(should (libmpdel-current-playlist-p 'current-playlist))
(should-not (libmpdel-current-playlist-p (libmpdel--stored-playlist-create :name "The Playlist")))
(should-not (libmpdel-current-playlist-p (libmpdel--artist-create :name "The Artist"))))
@@ -123,7 +126,7 @@
;;; Helper functions

(defmacro libmpdel--with-connection (&rest body)
(defmacro libmpdel-test--with-connection (&rest body)
"Execute BODY within a new fake MPD connection."
`(let ((libmpdel--msghandlers (list))
(libmpdel--connection (list))
@@ -135,18 +138,18 @@
(lambda (command) (setq commands (append commands (list command))))))
,@body)))

(ert-deftest libmpdel--raw-send-command-with-handler-with-a-string ()
(libmpdel--with-connection
(ert-deftest libmpdel-test--raw-send-command-with-handler-with-a-string ()
(libmpdel-test--with-connection
(libmpdel--raw-send-command-with-handler "command")
(should (equal "command" (car commands)))))

(ert-deftest libmpdel--raw-send-command-with-handler-with-a-list ()
(libmpdel--with-connection
(ert-deftest libmpdel-test--raw-send-command-with-handler-with-a-list ()
(libmpdel-test--with-connection
(libmpdel--raw-send-command-with-handler '("%s foo %S" "a" "b"))
(should (equal "a foo \"b\"" (car commands)))))

(ert-deftest libmpdel--raw-send-command-with-handler-update-handlers ()
(libmpdel--with-connection
(ert-deftest libmpdel-test--raw-send-command-with-handler-update-handlers ()
(libmpdel-test--with-connection
(ert-with-test-buffer ()
(libmpdel--raw-send-command-with-handler "command" 'foo)
(let ((handler (car libmpdel--msghandlers)))
@@ -154,17 +157,17 @@
(should (eql 'foo (cl-second handler)))
(should (eql (current-buffer) (cl-third handler)))))))

(ert-deftest libmpdel--raw-send-command-with-handler-add-ignore-handler ()
(libmpdel--with-connection
(ert-deftest libmpdel-test--raw-send-command-with-handler-add-ignore-handler ()
(libmpdel-test--with-connection
(libmpdel--raw-send-command-with-handler "command")
(let ((handler (car libmpdel--msghandlers)))
(should (eql #'libmpdel--msghandler-ignore (cl-second handler))))))

(ert-deftest libmpdel--message-filter-activates-saved-buffer ()
(ert-deftest libmpdel-test--message-filter-activates-saved-buffer ()
(let* ((expected-buffer nil)
(actual-buffer nil)
(handler (lambda (_) (setq actual-buffer (current-buffer)))))
(libmpdel--with-connection
(libmpdel-test--with-connection
(ert-with-test-buffer ()
(setq expected-buffer (current-buffer))
(libmpdel--raw-send-command-with-handler "foo" handler)
@@ -173,11 +176,11 @@
(should (bufferp actual-buffer))
(should (equal expected-buffer actual-buffer)))))))

(ert-deftest libmpdel--message-filter-keeps-current-buffer-if-saved-one-died ()
(ert-deftest libmpdel-test--message-filter-keeps-current-buffer-if-saved-one-died ()
(let* ((dead-buffer nil)
(actual-buffer nil)
(handler (lambda (_) (setq actual-buffer (current-buffer)))))
(libmpdel--with-connection
(libmpdel-test--with-connection
(ert-with-test-buffer ()
(setq dead-buffer (current-buffer))
(libmpdel--raw-send-command-with-handler "foo" handler))
@@ -187,12 +190,12 @@
(should-not (equal dead-buffer actual-buffer))
(should (equal (current-buffer) actual-buffer))))))

(ert-deftest libmpdel--msghandler-status-updates-volume ()
(libmpdel--with-connection
(ert-deftest libmpdel-test--msghandler-status-updates-volume ()
(libmpdel-test--with-connection
(libmpdel--msghandler-status '((volume . "42")))
(should (equal (libmpdel-volume) "42"))))

(ert-deftest libmpdel-extract-data ()
(ert-deftest libmpdel-test-extract-data ()
(should (equal '()
(libmpdel--extract-data "OK\n")))
(should (equal '((changed . "playlist"))
@@ -202,7 +205,7 @@
(should (equal '((volume . "100") (repeat . "0"))
(libmpdel--extract-data "volume: 100\nrepeat: 0\nOK\n"))))

(ert-deftest libmpdel-string<-ignore-case ()
(ert-deftest libmpdel-test-string<-ignore-case ()
(should (libmpdel--string<-ignore-case "a" "b"))
(should (libmpdel--string<-ignore-case "a" "B"))
(should (libmpdel--string<-ignore-case "A" "b"))
@@ -210,17 +213,17 @@
(should-not (libmpdel--string<-ignore-case "B" "a"))
(should-not (libmpdel--string<-ignore-case "b" "A")))

(ert-deftest libmpdel-time-to-string ()
(ert-deftest libmpdel-test-time-to-string ()
(should (string= (libmpdel-time-to-string nil) "0"))
(should (string= (libmpdel-time-to-string "2.230") "00:02"))
(should (string= (libmpdel-time-to-string "84.450") "01:24"))
(should (string= (libmpdel-time-to-string "3623.23") "60:23")))

(ert-deftest libmpdel-getting-and-setting-play-state ()
(ert-deftest libmpdel-test-getting-and-setting-play-state ()
(libmpdel--set-play-state "play")
(should (equal (libmpdel-play-state) 'play)))

(ert-deftest libmpdel-setting-play-state-run-hook ()
(ert-deftest libmpdel-test-setting-play-state-run-hook ()
(let* ((fn-executed 0)
(fn (lambda () (cl-incf fn-executed))))
(add-hook 'libmpdel-player-changed-hook fn)
@@ -229,7 +232,7 @@
(libmpdel--set-play-state "pause")
(should (equal fn-executed 2))))

(ert-deftest libmpdel-setting-play-state-run-hook-only-once ()
(ert-deftest libmpdel-test-setting-play-state-run-hook-only-once ()
(let* ((fn-executed 0)
(fn (lambda () (cl-incf fn-executed))))
(setq libmpdel-player-changed-hook nil)
@@ -239,14 +242,14 @@
(libmpdel--set-play-state "play")
(should (equal fn-executed 1))))

(ert-deftest libmpdel-getting-and-setting-volume ()
(ert-deftest libmpdel-test-getting-and-setting-volume ()
(libmpdel--set-volume "50")
(should (string= (libmpdel-volume) "50")))

;;; Public functions

(ert-deftest libmpdel-entries ()
(ert-deftest libmpdel-test-entries ()
(should (equal '("A" "B")
(libmpdel-entries '((Album . "A") (Album . "B")) 'Album)))
(should (equal '("B" "A")
@@ -256,7 +259,7 @@
(should (equal '("Bar")
(libmpdel-entries '((Album . "A") (Foo . "Bar") (Album . "B")) 'Foo))))

(ert-deftest libmpdel-sorted-entries ()
(ert-deftest libmpdel-test-sorted-entries ()
(should (equal '("A" "B")
(libmpdel-sorted-entries '((Album . "A") (Album . "B")) 'Album)))
(should (equal '("A" "B")
@@ -266,7 +269,7 @@
(should (equal '("Bar")
(libmpdel-sorted-entries '((Album . "A") (Foo . "Bar") (Album . "B")) 'Foo))))

(ert-deftest libmpdel-group-data ()
(ert-deftest libmpdel-test-group-data ()
(should (equal '(((Album . "1 Album") (Title . "1 Title"))
((Album . "2 Album") (Title . "2 Title")))
(libmpdel-group-data '((Album . "1 Album")
@@ -274,10 +277,10 @@
(Album . "2 Album")
(Title . "2 Title"))))))

(ert-deftest libmpdel-group-data-of-nil-is-nil ()
(ert-deftest libmpdel-test-group-data-of-nil-is-nil ()
(should (null (libmpdel-group-data nil))))

(ert-deftest libmpdel-equal ()
(ert-deftest libmpdel-test-equal ()
(let* ((artist1 (libmpdel--artist-create :name "artist1"))
(artist1-bis (libmpdel--artist-create :name "artist1"))
(artist2 (libmpdel--artist-create :name "artist2"))
@@ -323,8 +326,9 @@
(should (not (libmpdel-equal song1 song2)))
(should (not (libmpdel-equal song2 song1)))))

;;; Playlist queries

(provide 'libmpel-test)
(provide 'libmpdel-test)
;;; libmpdel-test.el ends here

;; Local Variables:
;; nameless-current-name: "libmpdel-test"
;; End:

Loading…
Cancel
Save