Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bazel tests #1601

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

bcsgh
Copy link
Contributor

@bcsgh bcsgh commented Mar 17, 2025

  • Tweak runjsontests.py to allow passing single test case files (which s way easier to get than a dir name under Bazel).
  • Add tests to the Bazel builds.

Note:

  • This is on top of Make the build configuration under Bazel more correct. #1600
  • Because Bazle doesn't allow directly referencing source file from test rules (the path they end up in is an implementation detail) it ends up harder to find the directory that contains the test cases than to find the path for a single test case. To deal with that, this PR creates one test rule per test case so that each command only need the actual file path. That ends up looking a little odd, but is has the collateral benefit of surfacing exactly what does, doesn't work.

Testing:

This pass with all 4 combinations:

for i in true false ; do
  for e in true false ; do
    bazel test --@//:use_exception=${e} --@//:has_int64=${i} ...
  done
done

While working on this, I intentionally broke a pass and fail test in each directory to be sure those resulted in a failing test rule, and they did.

bcsgh added 4 commits March 18, 2025 17:08
…th defaults that match the existing Bazel build.

Switch //:jsoncpp from using copts ro defines for JSON_USE_EXCEPTION and JSON_HAS_INT64 so that rules that depend on it get the same config.
Make src/test_lib_json/fuzz.cpp respect JSON_USE_EXCEPTION.
@bcsgh bcsgh force-pushed the bcsgh/bazel-tests branch from d13b741 to 0383d14 Compare March 19, 2025 00:16
Copy link
Contributor

@baylesj baylesj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is in Draft still but here's some early feedback.

tests = [
test for test in tests
if os.path.basename(test) not in known and
os.path.basename(os.path.dirname(test)) == "jsonchecker"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add this check here for "jsonchecker", then tests only consists of jsonchecker tests, meaning that the line check on 113 is no longer needed, since is_json_checker_test is always True, right?

Copy link
Contributor Author

@bcsgh bcsgh Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. (Most of the tests were incorrectly no-ops.) Fixed.

exports_files(["LICENSE"])

bool_flag(
name = "use_exception",
build_setting_default = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceptions should be on by default, I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an abstract question, that's debatable (as in there are good arguments either way). But, given that the existing Bazel build has them off by default, I think backwards compatibility requires keeping them that way.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: probably a discussion that should be on the record of #1601 (unless you want to merge just this PR and not that one).

@bcsgh bcsgh marked this pull request as ready for review March 19, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants