-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load(":version_test.bzl", "version_test_rules") | ||
load("//nickel/private:toolchains_repo.bzl", "PLATFORMS") | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
|
||
[selects.config_setting_group( | ||
name = "version_test_{}".format(platform), | ||
match_all = meta.compatible_with, | ||
) for [ | ||
platform, | ||
meta, | ||
] in PLATFORMS.items()] | ||
|
||
version_test_rules(name = "nickel") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Testing that Nickel versions are what they claim to be""" | ||
|
||
load("//nickel/private:versions.bzl", "TOOL_VERSIONS") | ||
load("//nickel/private:toolchains_repo.bzl", "PLATFORMS") | ||
|
||
def _version_pattern(version): | ||
if version == "1.0.0": | ||
return "nickel-lang 1.0.0" | ||
if version == "1.1.1": | ||
return "unexpected argument" | ||
return "nickel-lang-cli nickel {0}".format(version) | ||
|
||
def _version_test_extension(_ctx): | ||
all_versions_repository(name = "all_nickel_versions") | ||
|
||
version_test = module_extension( | ||
implementation = _version_test_extension, | ||
) | ||
|
||
def _all_versions_repository(repository_ctx): | ||
for [version, artifacts] in TOOL_VERSIONS.items(): | ||
files_list = [] | ||
|
||
for [name, artifact] in artifacts.items(): | ||
repository_ctx.download( | ||
url = artifact["url"], | ||
output = "{dir}/{name}".format(dir = version, name = name), | ||
executable = True, | ||
integrity = artifact["hash"], | ||
) | ||
files_list.append("\"{}\"".format(name)) | ||
|
||
build_content = """#Generated by nickel/tets/version_test.bzl | ||
exports_files([{}]) | ||
""".format(", ".join(files_list)) | ||
repository_ctx.file("{}/BUILD.bazel".format(version), build_content) | ||
|
||
all_versions_repository = repository_rule( | ||
_all_versions_repository, | ||
doc = "Fetch all Nickel artifacts for testing", | ||
) | ||
|
||
def version_test_rules(name): | ||
"""Assemble testing rules to check Nickel versions are what they claim to be | ||
Args: | ||
name: base name for all the tests | ||
""" | ||
for version in TOOL_VERSIONS.keys(): | ||
tools = {} | ||
args = {} | ||
|
||
for platform in PLATFORMS.keys(): | ||
nickel_target = "@all_nickel_versions//{0}:nickel-{1}".format(version, platform) | ||
tools[":version_test_{}".format(platform)] = [nickel_target] | ||
args[":version_test_{}".format(platform)] = ["$(location {})".format(nickel_target), _version_pattern(version)] | ||
|
||
version_underscore = version.replace(".", "_") | ||
native.sh_test( | ||
name = "{}_{}_version_test".format(name, version_underscore), | ||
data = select(tools), | ||
args = select(args), | ||
srcs = ["version_test.sh"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_nickel=$1 | ||
_version_pattern=$2 | ||
|
||
("${_nickel}" --version 2>&1 || true) | grep "${_version_pattern}" |