Commit Graph

33 Commits

Author SHA1 Message Date
Vinh Tran 1bbb388780
Update unittest_doc.md with analysistest and loadingtest modules (#370)
Co-authored-by: Alexandre Rostovtsev <arostovtsev@google.com>
2022-08-26 09:21:43 -04:00
Vinh Tran 69b4636956
Fix doc error for analystest.begin (#369)
Co-authored-by: Alexandre Rostovtsev <arostovtsev@google.com>
2022-08-25 17:47:50 -04:00
UebelAndre cdd0afdfe6
Fixed positional args for unittest targets (#352)
Followup to https://github.com/bazelbuild/bazel-skylib/pull/343
2022-02-10 17:55:11 -05:00
UebelAndre 2bc90bdf7d
Allow unit test rules to be documented (#343)
I find it more ergonomic to add notes or a description about a test to a `doc` attribute, similar to other rules, vs a comment block above it or in the `impl` function docstring. Hopefully this can improve the readability of test rules.
2022-02-10 17:00:29 -05:00
Kevin Kress 7270e3b345
Add support for 'loading' unit tests, which evaluate a LOADING phase. (#347)
This is a relatively simple addition to unittest that statically creates rules
that either explicitly fail or not depending on if the test case is valid during
LOADING phase of bazel.  The test conditions are evaluated entirely in loading
phase, but if we want an actual test to fail rather than just `fail()` killing
the build, we can use this to assert state and report test failures.
2022-02-10 16:03:48 -05:00
Samuel Freilich 506c17293e
Improve escaping in unittest failure message (#320) 2021-10-04 12:03:48 -04:00
Daniel Wagner-Hall 08398cdc99
Allow specifying additional aspects to tut (#299) 2021-09-23 16:21:58 -04:00
David Sanderson ed7f03cde6
Enable unittest.suite to accept partial calls of test rules (#276)
* Enable unittest.suite to accept partial calls of rules

This permits using `unittest.suite` with test rules that have nondefault
attributes, while retaining compatibility with current usage.

For instance, this permits setting a `timeout` on each test in a
`unittest.suite`.  Previously, all tests in a `unittest.suite` would
have the default timeout, with no good way to alter this.  This
made it hard to eliminate all the warnings produced from using the
`--test_verbose_timeout_warnings` bazel option.

While timeouts were the motivation, the solution here is not specific
to timeouts. It will permit arbitrary additional arguments to the test
rules in a `unittest.suite`.

Fixes #98

* Respond to review feedback.

* Document a breaking change in bazel that this code needs to be aware of.
2020-11-12 21:04:39 -05:00
David Sanderson 56ec790c9b
Address latent buildifier issues. (#278)
In https://buildkite.com/bazel/bazel-skylib/builds/1240#annotation-buildifier
I noticed buildifier issues unrelated to my PR.
This PR attempts to address these latent buildifier issues.
2020-09-25 22:32:06 +02:00
Ivo List dc080e9516
Prettify failure message of asserts.set_equals. (#263)
Before, when comparing large sets, the message dumped the whole set. Now it additionally prints missing and unexpected elements.
2020-08-11 14:52:32 +02:00
Andrew Z Allen 3b666f525d
Address lint errors (#254) 2020-06-19 19:49:52 +02:00
Thomas Van Lenten add8e42934
Run buildifier over the directory. (#235)
Using the 1.0 release.

```
buildifier -r .
```
2020-02-18 13:17:37 -05:00
Laurent Le Brun e583e822a0
Remove old_sets.bzl (#231)
It has been deprecated for a while, the code is not really compatible with Bazel depset-related changes.
2020-02-03 16:39:21 +01:00
c-parsons cff8af42e9
Remove genfiles_dir retrieval method (#203)
genfiles_dir has been the same as bin_dir for several Bazel releases, and is
being fully removed in upcoming Bazel release.
2019-10-08 15:46:35 -04:00
Samuel Freilich 376680d276 Expose target_under_test's bin and genfiles path (#202)
The output directories for the target under test may differ when the target is under a config transition (config_settings is passed to analysistest.make). Since analysis tests may assert about the command-line of generated actions, and those command-lines may contain paths to output files, this is useful information to expose.
2019-10-08 12:39:11 -04:00
Samuel Freilich f1475299af Avoid some repetition in _make_analysis_test (#197) 2019-10-04 11:19:43 -04:00
Gabe Giosia 720f59405d Pass `fragments` through to analysis tests rule constructors. (#190)
Passing fragments through to the rule allows rules to access language specific features.
2019-10-02 14:14:17 -04:00
Thomas Van Lenten d2cf1cc2bc
`print`->`fail` and suppress the warning in another case. (#177) 2019-07-22 13:25:00 -04:00
c-parsons 202db59ecc
Make sets.bzl point to new_sets.bzl instead of old_sets.bzl (#158)
* Make sets.bzl point to new_sets.bzl instead of old_sets.bzl

new_sets.bzl and old_sets.bzl should be removed in the following skylib release.

Fixes #155.

* update and rename test suites
2019-05-28 17:54:22 -04:00
Sergio Campamá ffad33e9bf Pass through an attribute arguments to `analysistest.make`. (#140)
This allows `analysistest.make` rules to be parameterized.
2019-05-03 16:24:20 -04:00
c-parsons a2ec47917b
fix a number of warnings found by Starlark analyzer (#114) 2019-02-22 17:44:48 -05:00
c-parsons a35b13a1c9
analysistest API for retrieval of actions registered by target under test 2019-02-20 15:32:47 -05:00
c-parsons 6bb8994a03
Add analysis-test test framework (#110)
This framework allows for easy creation of unittest-like tests to make assertions
on the provider-values returned by real targets.
2019-02-14 16:54:42 -05:00
c-parsons 197d869482
fix various linter errors (#93) 2019-01-14 12:41:43 -05:00
Thomas Van Lenten 4795fd6146 Run buildifier --lint=fix over the files. (#88)
Fixes some dict order issues with the current version of buildifier.
2019-01-02 14:47:44 -08:00
László Csomor daf5137022
unittest.bzl: supports Windows (#84)
In this commit:

- change unittest.bzl to declare a named output
  file instead of relying on the deprecated [1]
  default output name (ctx.outputs.executable).

- define a new toolchain_type and toolchain rules
  for cmd.exe and for Bash (basically Windows and
  non-Windows)

- register the new toolchains in workspace.bzl

- let unittest.make-created test rules require the
  new toolchain_type

- write the test output script as a Windows batch
  script or as a Shell script, depending on the
  selected toolchain

This PR enables the Bazel team to break the Bash
dependency (for test execution) on Windows, and
can run Starlark unittests with the new,
Windows-native test wrapper (still under
development).

See https://github.com/bazelbuild/bazel/issues/5508
2018-12-04 16:14:08 +01:00
Thomas Van Lenten 8c575e737f Fix up lint issues. (#77)
Fixed via `buildifier --lint=fix` with buildifier 0.19.2.1
2018-11-26 17:31:29 -05:00
bttk 3360231ec0 Upgrade to the new actions API (#65)
In future Bazel releases ctx.file_action will be removed.
ctx.action.write should be used instead.

With this change tests pass even if --incompatible_new_actions_api
is used.

Bazel issue:
https://github.com/bazelbuild/bazel/issues/5825
2018-11-13 11:22:18 +01:00
c-parsons 6e2d7e4a75
Rename a number of instances of 'skylark' to 'starlark' or 'bzl'
Most notably, this renames/moves a few important identifiers:

//:skylark_library.bzl -> //:bzl_library.bzl
skylark_library -> bzl_library
SkylarkLibraryInfo -> StarlarkLibraryInfo
2018-09-28 09:09:18 -04:00
Thomas Van Lenten e5203c0f5d Reformat .bzl files with buildifier and add format check.
Buildifier 0.12.0 includes initial support for reformatting .bzl files.
- Reformat all the bzl files.
- Expand the travis check to check the .bzl files also.
2018-06-13 10:58:35 -04:00
Thomas Van Lenten 2d356cf857 Doc and code fixes found via skylint. (#38)
* Fix up the skylint warning about depset usage.

* Remove the reassignment of max_bazel_version.

This was flagged by skylint, the reality is _is_at_most() does the parsing
so it shouldn't be parsed before sent on the way.

* Fix up the skylint warning about depset usage.

* Fixup the skylint warning about re-exports.

Just move to the explicit re-export form.

* Fix the fail() call to use the right variable.

skylint flagged this variable as undefined, but it it seems like this
was never right and should have been "key" all along.

* Fixup docstring formatting for skylint.
2018-04-26 12:08:01 -04:00
Nicholas Titcombe 0b40ea7b13 Introduce new_sets.bzl (#32)
This version is hash-based (implemented on top of a dictionary) and doesn't suffer the performance problems of the current version. It will eventually replace the old one after a deprecation period.
2018-04-20 14:44:25 -07:00
Tony Allevato 82b3ad6e9e Initial check-in. 2017-10-10 07:59:31 -07:00