diff options
author | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
commit | f723b8b878a3c4a4687b9e337a875500bebb39b1 (patch) | |
tree | e85204cf042c355e90cff61c111e7d8cd15df311 /third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl | |
parent | 2eb1dc26e42ffbdc168f05ef744bd4b4f3e4c36f (diff) |
feat(third_party/bazel): Check in rules_haskell from Tweag r/17
Diffstat (limited to 'third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl')
-rw-r--r-- | third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl b/third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl new file mode 100644 index 000000000000..58a3f400adbe --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl @@ -0,0 +1,83 @@ +load( + "@bazel_skylib//lib:unittest.bzl", + "asserts", + unit = "unittest", +) +load("//haskell:private/actions/link.bzl", "create_rpath_entry", "parent_dir_path") +load("//haskell:private/list.bzl", "list") + +def parent_dir_path_test_impl(ctx): + env = unit.begin(ctx) + asserts.equals( + env, + expected = ctx.attr.output, + actual = parent_dir_path(ctx.attr.filename), + ) + unit.end(env) + +parent_dir_path_test = unit.make( + parent_dir_path_test_impl, + attrs = { + "filename": attr.string(), + "output": attr.string_list(), + }, +) + +def create_rpath_entry_test_impl(ctx): + env = unit.begin(ctx) + asserts.equals( + env, + expected = ctx.attr.output, + actual = create_rpath_entry( + struct( + short_path = ctx.attr.binary_short_path, + ), + struct( + short_path = ctx.attr.dependency_short_path, + ), + keep_filename = ctx.attr.keep_filename, + prefix = ctx.attr.prefix, + ), + ) + unit.end(env) + +create_rpath_entry_test = unit.make( + create_rpath_entry_test_impl, + attrs = { + "binary_short_path": attr.string(), + "dependency_short_path": attr.string(), + "keep_filename": attr.bool(default = False, mandatory = False), + "prefix": attr.string(default = "", mandatory = False), + "output": attr.string(), + }, +) + +def compare_x(el): + return el.x + +def dedup_on_test_impl(ctx): + env = unit.begin(ctx) + asserts.equals( + env, + expected = [], + actual = list.dedup_on(compare_x, []), + ) + asserts.equals( + env, + expected = [struct(x = 3)], + actual = list.dedup_on( + compare_x, + [struct(x = 3), struct(x = 3), struct(x = 3)], + ), + ) + asserts.equals( + env, + expected = [struct(x = 3), struct(x = 4), struct(x = 5)], + actual = list.dedup_on( + compare_x, + [struct(x = 3), struct(x = 4), struct(x = 3), struct(x = 5), struct(x = 3)], + ), + ) + unit.end(env) + +dedup_on_test = unit.make(dedup_on_test_impl) |