about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/tests/unit-tests/tests.bzl
blob: 58a3f400adbe5a9d2bbb7db3ea5b4aae81920eab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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)