Skip to content

Commit

Permalink
Move tests from elisp/runfiles into tests/runfiles package.
Browse files Browse the repository at this point in the history
This reduces load-time dependencies for users of the elisp/runfiles package.
  • Loading branch information
phst committed Feb 28, 2025
1 parent 0c40558 commit 45cd7df
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ repos:
- id: pretty-format-json
- id: requirements-txt-fixer
- id: trailing-whitespace
exclude: '(\.(el|patch)|^elisp/runfiles/test-manifest|^index\.html)$'
exclude: '(\.(el|patch)|^tests/runfiles/test-manifest|^index\.html)$'
24 changes: 0 additions & 24 deletions elisp/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

load("//elisp:elisp_library.bzl", "elisp_library")
load("//elisp:elisp_test.bzl", "elisp_test")
load("//private:package_features.bzl", "PACKAGE_FEATURES")

package(
Expand All @@ -30,26 +29,3 @@ elisp_library(
outs = ["runfiles.elc"],
visibility = ["//visibility:public"],
)

TEST_DATA = [
"test.txt",
"test-lib.elc",
"test-manifest",
"test-mapping",
]

elisp_test(
name = "runfiles_test",
size = "small",
srcs = ["runfiles-test.el"],
args = ["%s=$(rlocationpath %s)" % (f, f) for f in TEST_DATA],
data = TEST_DATA,
deps = [":runfiles"],
)

elisp_library(
name = "test_lib",
testonly = True,
srcs = ["test-lib.el"],
outs = ["test-lib.elc"],
)
1 change: 1 addition & 0 deletions private/package_features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ visibility([
"//gazelle/testdata",
"//tests",
"//tests/pkg",
"//tests/runfiles",
])

# Features for all packages. These may not contain select expressions.
Expand Down
48 changes: 48 additions & 0 deletions tests/runfiles/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2020, 2021, 2024, 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//elisp:elisp_library.bzl", "elisp_library")
load("//elisp:elisp_test.bzl", "elisp_test")
load("//private:package_features.bzl", "PACKAGE_FEATURES")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:private"],
features = PACKAGE_FEATURES,
)

licenses(["notice"])

TEST_DATA = [
"test.txt",
"test-lib.elc",
"test-manifest",
"test-mapping",
]

elisp_test(
name = "runfiles_test",
size = "small",
srcs = ["runfiles-test.el"],
args = ["%s=$(rlocationpath %s)" % (f, f) for f in TEST_DATA],
data = TEST_DATA,
deps = ["//elisp/runfiles"],
)

elisp_library(
name = "test_lib",
testonly = True,
srcs = ["test-lib.el"],
outs = ["test-lib.elc"],
)
20 changes: 10 additions & 10 deletions elisp/runfiles/runfiles-test.el → tests/runfiles/runfiles-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

(require 'ert)

(defvar elisp/runfiles/rlocations
(defvar tests/runfiles/rlocations
(let ((table (make-hash-table :test #'equal)))
(while command-line-args-left
(pcase (pop command-line-args-left)
Expand All @@ -36,7 +36,7 @@
(ert-deftest elisp/runfiles/rlocation ()
(let* ((runfiles (elisp/runfiles/make))
(filename (elisp/runfiles/rlocation
(gethash "test.txt" elisp/runfiles/rlocations)
(gethash "test.txt" tests/runfiles/rlocations)
runfiles))
(process-environment (elisp/runfiles/env-vars runfiles)))
(should (cl-typep runfiles 'elisp/runfiles/runfiles))
Expand All @@ -63,7 +63,7 @@

(ert-deftest elisp/runfiles/special-chars/manifest ()
(let* ((manifest (elisp/runfiles/rlocation
(gethash "test-manifest" elisp/runfiles/rlocations)))
(gethash "test-manifest" tests/runfiles/rlocations)))
(runfiles (elisp/runfiles/make :manifest manifest
:directory "/invalid/")))
(pcase-dolist (`(,source ,target)
Expand All @@ -80,7 +80,7 @@

(ert-deftest elisp/runfiles/make/empty-file ()
(let* ((manifest (elisp/runfiles/rlocation
(gethash "test-manifest" elisp/runfiles/rlocations)))
(gethash "test-manifest" tests/runfiles/rlocations)))
(runfiles (elisp/runfiles/make :manifest manifest
:directory "/invalid/")))
(should-error (elisp/runfiles/rlocation "__init__.py" runfiles)
Expand All @@ -91,19 +91,19 @@
See https://github.com/bazelbuild/bazel/issues/14336 for
context."
(let* ((manifest (elisp/runfiles/rlocation
(gethash "test-manifest" elisp/runfiles/rlocations)))
(gethash "test-manifest" tests/runfiles/rlocations)))
(runfiles (elisp/runfiles/make :manifest manifest
:directory "/invalid/")))
(should (equal (elisp/runfiles/rlocation "foo/bar/baz" runfiles)
"/:runfiles/foo/bar/baz"))))

(ert-deftest elisp/runfiles/file-handler ()
(let* ((file-name-handler-alist file-name-handler-alist)
(rlocation (gethash "test.txt" elisp/runfiles/rlocations))
(rlocation (gethash "test.txt" tests/runfiles/rlocations))
(repository (string-trim-right rlocation (rx ?/ (* anychar))))
(virtual-repo-root (concat "/bazel-runfile:" repository))
(virtual-file (concat "/bazel-runfile:" rlocation))
(virtual-dir (concat virtual-repo-root "/elisp/")))
(virtual-dir (concat virtual-repo-root "/tests/")))
(elisp/runfiles/install-handler)
(should (rassq #'elisp/runfiles/file-handler file-name-handler-alist))
(should (eql (cl-count #'elisp/runfiles/file-handler file-name-handler-alist
Expand All @@ -123,20 +123,20 @@ context."
(should (equal (expand-file-name "runfiles/test.txt" virtual-dir)
virtual-file))
(should (equal (expand-file-name "runfiles/test.txt"
(concat virtual-repo-root "/elisp"))
(concat virtual-repo-root "/tests"))
virtual-file))
(should (equal (file-relative-name virtual-file virtual-dir)
"runfiles/test.txt"))
(should (equal (file-truename virtual-dir) virtual-dir))
(should (equal (abbreviate-file-name virtual-file) virtual-file))
(let ((load-path (list virtual-repo-root)))
(require 'elisp/runfiles/test-lib))))
(require 'tests/runfiles/test-lib))))

(ert-deftest elisp/runfiles/repo-mapping ()
(let ((temp-dir (make-temp-file "elisp-test-" :directory ".runfiles")))
(copy-file
(elisp/runfiles/rlocation
(gethash "test-mapping" elisp/runfiles/rlocations))
(gethash "test-mapping" tests/runfiles/rlocations))
(expand-file-name "_repo_mapping" temp-dir))
(let ((runfiles (elisp/runfiles/make :manifest "/invalid.manifest"
:directory temp-dir)))
Expand Down
6 changes: 3 additions & 3 deletions elisp/runfiles/test-lib.el → tests/runfiles/test-lib.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; test-lib.el --- test library for runfiles test -*- lexical-binding: t; -*-

;; Copyright 2021 Google LLC
;; Copyright 2021, 2025 Google LLC
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,9 @@

;;; Commentary:

;; Test library for //elisp/runfiles:runfiles_test.
;; Test library for //tests/runfiles:runfiles_test.

;;; Code:

(provide 'elisp/runfiles/test-lib)
(provide 'tests/runfiles/test-lib)
;;; test-lib.el ends here
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 45cd7df

Please sign in to comment.