Skip to content

Commit

Permalink
Add a unit test for the environment variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phst committed Dec 3, 2023
1 parent a285300 commit 97d6903
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
9 changes: 5 additions & 4 deletions elisp/ert/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//elisp:defs.bzl", "elisp_library")
load("//elisp:defs.bzl", "elisp_library", "elisp_test")

package(
default_applicable_licenses = ["//:license"],
Expand All @@ -30,7 +29,9 @@ elisp_library(
visibility = ["//visibility:public"],
)

build_test(
elisp_test(
name = "runner_test",
targets = [":runner"],
size = "small",
srcs = ["runner-test.el"],
deps = [":runner"],
)
66 changes: 66 additions & 0 deletions elisp/ert/runner-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
;;; runner-test.el --- unit tests for runner.el -*- lexical-binding: t; -*-

;; Copyright 2023 Philipp Stephani
;;
;; 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
;;
;; http://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.

;;; Commentary:

;; Unit tests for runner.el.

;;; Code:

(ert-deftest environment ()
"Test that the environment is set up as expected.
See URL
‘https://bazel.build/reference/test-encyclopedia#initial-conditions’."
(should (equal (getenv "HOME") (getenv "TEST_TMPDIR")))
(should-not (getenv "LANG"))
(should-not (getenv "LANGUAGE"))
(should-not (getenv "LC_ALL"))
(should-not (getenv "LC_COLLATE"))
(should-not (getenv "LC_CTYPE"))
(should-not (getenv "LC_MESSAGES"))
(should-not (getenv "LC_MONETARY"))
(should-not (getenv "LC_NUMERIC"))
(should-not (getenv "LC_TIME"))
(should (equal (getenv "LOGNAME") (getenv "USER")))
(should (equal (getenv "PATH") "/usr/bin:/usr/sbin:/bin:/sbin"))
(should (equal (getenv "PWD") (expand-file-name (getenv "TEST_WORKSPACE")
(getenv "TEST_SRCDIR"))))
(should (equal (getenv "SHLVL") "2"))
(should-not (getenv "TEST_RANDOM_SEED"))
(should-not (getenv "TEST_RUN_NUMBER"))
(should (equal (getenv "TEST_TARGET") "//elisp/ert:runner_test"))
(should (equal (getenv "TEST_SIZE") "small"))
(should (equal (getenv "TEST_TIMEOUT") "60"))
(should-not (getenv "TEST_SHARD_INDEX"))
(should-not (getenv "TEST_SHARD_STATUS_FILE"))
(should (getenv "TEST_SRCDIR"))
(should (file-name-absolute-p (getenv "TEST_SRCDIR")))
(should (file-readable-p (getenv "TEST_SRCDIR")))
(should-not (getenv "TEST_TOTAL_SHARDS"))
(should (getenv "TEST_TMPDIR"))
(should (file-name-absolute-p (getenv "TEST_TMPDIR")))
(should (file-readable-p (getenv "TEST_TMPDIR")))
(should (file-writable-p (getenv "TEST_TMPDIR")))
;; Support Bzlmod and legacy mode.
(should (member (getenv "TEST_WORKSPACE") '("_main" "phst_rules_elisp")))
(should-not (getenv "TESTBRIDGE_TEST_ONLY"))
(should (equal (getenv "TZ") "UTC"))
(should (getenv "USER"))
(should (equal (getenv "USER") (user-login-name)))
(should (getenv "XML_OUTPUT_FILE"))
(should (getenv "BAZEL_TEST")))

;;; runner-test.el ends here

0 comments on commit 97d6903

Please sign in to comment.