Giter Site home page Giter Site logo

Comments (2)

yesudeep avatar yesudeep commented on July 24, 2024

Ah, never mind. figured it out. One of the tests needs exception support built in.
Fixed my build file and now all tests pass:

❯ bazel test "@frozen//:all_tests" //third_party/cc/test:frozen_test
INFO: Analyzed 11 targets (0 packages loaded, 0 targets configured).
INFO: Found 11 test targets...
INFO: Elapsed time: 0.172s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
//third_party/cc/test:frozen_test                               (cached) PASSED in 0.3s
@frozen//:algorithms_test                                       (cached) PASSED in 1.2s
@frozen//:map_test                                              (cached) PASSED in 1.2s
@frozen//:rand_test                                             (cached) PASSED in 1.1s
@frozen//:set_test                                              (cached) PASSED in 1.1s
@frozen//:str_set_test                                          (cached) PASSED in 1.1s
@frozen//:str_test                                              (cached) PASSED in 1.1s
@frozen//:unordered_map_str_test                                (cached) PASSED in 1.2s
@frozen//:unordered_map_test                                    (cached) PASSED in 1.1s
@frozen//:unordered_set_test                                    (cached) PASSED in 1.1s
@frozen//:unordered_str_set_test                                (cached) PASSED in 1.2s

INFO: Build completed successfully, 1 total action

Updated build file for anybody who needs it:

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

licenses(["notice"])  # Apache 2.0

exports_files(["LICENSE"])

FROZEN_HEADERS = [
    "include/frozen/algorithm.h",
    "include/frozen/bits/algorithms.h",
    "include/frozen/bits/basic_types.h",
    "include/frozen/bits/constexpr_assert.h",
    "include/frozen/bits/elsa.h",
    "include/frozen/bits/exceptions.h",
    "include/frozen/bits/pmh.h",
    "include/frozen/bits/version.h",
    "include/frozen/map.h",
    "include/frozen/random.h",
    "include/frozen/set.h",
    "include/frozen/string.h",
    "include/frozen/unordered_map.h",
    "include/frozen/unordered_set.h",
]

FROZEN_COPTS = [
    "-O3",
    "-funroll-loops",
]

# Build frozen both with and without exceptions
cc_library(
    name = "frozen",
    hdrs = FROZEN_HEADERS,
    copts = FROZEN_COPTS,
    defines = [
        "FROZEN_NO_EXCEPTIONS",
    ],
    includes = [
        "include",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "frozen_with_exceptions",
    hdrs = FROZEN_HEADERS,
    copts = FROZEN_COPTS,
    includes = [
        "include",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

test_suite(
    name = "all_tests",
    tests = [
        ":algorithms_test",
        ":map_test",
        ":rand_test",
        ":set_test",
        ":str_set_test",
        ":str_test",
        # Bazel can't run CTest. Implemented our own death test using googletest.
        # See: frozen_test.cc
        # ":unordered_map_no_exceptions_test",
        ":unordered_map_str_test",
        ":unordered_map_test",
        ":unordered_set_test",
        ":unordered_str_set_test",
    ],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "test_runner",
    srcs = [
        "tests/test_main.cpp",
    ],
    hdrs = [
        "tests/bench.hpp",
        "tests/catch.hpp",
    ],
)

# cc_test(
#     name = "unordered_map_no_exceptions_test",
#     size = "small",
#     srcs = [
#         "tests/no_exceptions.cpp",
#     ],
#     visibility = ["//visibility:public"],
#     deps = [
#         ":frozen",
#         # ":test_runner",
#     ],
# )

cc_test(
    name = "algorithms_test",
    size = "small",
    srcs = [
        "tests/test_algorithms.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "map_test",
    size = "small",
    srcs = [
        "tests/test_map.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "rand_test",
    size = "small",
    srcs = [
        "tests/test_rand.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "set_test",
    size = "small",
    srcs = [
        "tests/test_set.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "str_test",
    size = "small",
    srcs = [
        "tests/test_str.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "str_set_test",
    size = "small",
    srcs = [
        "tests/test_str_set.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "unordered_map_test",
    size = "small",
    srcs = [
        "tests/test_unordered_map.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen_with_exceptions",
        ":test_runner",
    ],
)

cc_test(
    name = "unordered_map_str_test",
    size = "small",
    srcs = [
        "tests/test_unordered_map_str.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "unordered_set_test",
    size = "small",
    srcs = [
        "tests/test_unordered_set.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

cc_test(
    name = "unordered_str_set_test",
    size = "small",
    srcs = [
        "tests/test_unordered_str_set.cpp",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":frozen",
        ":test_runner",
    ],
)

Implemented a death test separately for my repository:

cc_test(
    name = "frozen_test",
    size = "small",
    srcs = ["frozen_test.cc"],
    visibility = ["//visibility:public"],
    deps = [
        "@com_google_googletest//:gtest_main",
        "@frozen",
    ],
)

frozen_test.cc:

#include "frozen/unordered_map.h"
#include "gtest/gtest.h"

TEST(FrozenTest, OurFrozenIsBuiltWithoutExceptions) {
  constexpr frozen::unordered_map<int, int, 1> map{{1, 4}};
  ASSERT_DEATH(map.at(3), "");
}

Thank you for an awesome library.

Please feel free to close the bug.

from frozen.

serge-sans-paille avatar serge-sans-paille commented on July 24, 2024

I'd welcome the patch for the death test, feel free to propose a PR for it!

from frozen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.