github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/tests/cli/env_variables_test.bzl (about)

     1  load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
     2  load("@bazel_skylib//rules:analysis_test.bzl", "analysis_test")
     3  load("//:def.bzl", "gazelle")
     4  
     5  def _invalid_var_failure_test_impl(ctx):
     6      env = analysistest.begin(ctx)
     7      var_name = ctx.attr.var_name
     8      if var_name == None:
     9          unittest.fail(env, "var_name can't be null")
    10      asserts.expect_failure(env, "Invalid environmental variable name: '%s'" % var_name)
    11      return analysistest.end(env)
    12  
    13  invalid_var_failure_test = analysistest.make(
    14      _invalid_var_failure_test_impl,
    15      expect_failure = True,
    16      attrs = {
    17          "var_name": attr.string(),
    18      },
    19  )
    20  
    21  def env_variables_test_suite():
    22      gazelle(
    23          name = "gazelle-valid-env-variables",
    24          env = {
    25              "SOME_VARIABLE": "1",
    26              "YET_ANOTHER_VARIABLE_0": "2",
    27              "_another_variable": "3",
    28          },
    29          tags = ["manual"],
    30      )
    31  
    32      analysis_test(
    33          name = "valid_env_variables_test",
    34          targets = [
    35              ":gazelle-valid-env-variables",
    36          ],
    37      )
    38  
    39      gazelle(
    40          name = "gazelle-numbers-in-var-name",
    41          env = {
    42              "0foo": "",
    43          },
    44          tags = ["manual"],
    45      )
    46  
    47      invalid_var_failure_test(
    48          name = "env_variable_name_cant_start_with_numbers_test",
    49          target_under_test = ":gazelle-numbers-in-var-name",
    50          var_name = "0foo",
    51      )
    52  
    53      gazelle(
    54          name = "gazelle-empty-var-name",
    55          env = {
    56              "": "",
    57          },
    58          tags = ["manual"],
    59      )
    60  
    61      invalid_var_failure_test(
    62          name = "env_variable_name_cant_be_empty",
    63          target_under_test = ":gazelle-empty-var-name",
    64          var_name = "",
    65      )