1 ;;; gyp-tests.el - unit tests for gyp-mode.
3 ;; Copyright (c) 2012 Google Inc. All rights reserved.
4 ;; Use of this source code is governed by a BSD-style license that can be
5 ;; found in the LICENSE file.
7 ;; The recommended way to run these tests is to run them from the command-line,
8 ;; with the run-unit-tests.sh script.
14 (defconst samples (directory-files "testdata" t ".gyp$")
15 "List of golden samples to check")
17 (defun fontify (filename)
19 (insert-file-contents-literally filename)
21 (font-lock-fontify-buffer)
24 (defun read-golden-sample (filename)
26 (insert-file-contents-literally (concat filename ".fontified"))
27 (read (current-buffer))))
29 (defun equivalent-face (face)
30 "For the purposes of face comparison, we're not interested in the
31 differences between certain faces. For example, the difference between
32 font-lock-comment-delimiter and font-lock-comment-face."
34 ((font-lock-comment-delimiter-face) font-lock-comment-face)
37 (defun text-face-properties (s)
38 "Extract the text properties from s"
39 (let ((result (list t)))
40 (dotimes (i (length s))
41 (setq result (cons (equivalent-face (get-text-property i 'face s))
45 (ert-deftest test-golden-samples ()
46 "Check that fontification produces the same results as the golden samples"
47 (dolist (sample samples)
48 (let ((golden (read-golden-sample sample))
49 (fontified (fontify sample)))
50 (should (equal golden fontified))
51 (should (equal (text-face-properties golden)
52 (text-face-properties fontified))))))
54 (defun create-golden-sample (filename)
55 "Create a golden sample by fontifying filename and writing out the printable
56 representation of the fontified buffer (with text properties) to the
58 (with-temp-file (concat filename ".fontified")
59 (print (fontify filename) (current-buffer))))
61 (defun create-golden-samples ()
62 "Recreate the golden samples"
63 (dolist (sample samples) (create-golden-sample sample)))