Commit Graph

73 Commits

Author SHA1 Message Date
Kevin Kress cc51024fc2
Add subpackages module to skylib to support new bazel native.subpackages (#348) 2022-04-04 17:56:21 -04:00
Barry McNamara 8334f938c1
Implement omit and pick dicts functions. (#304) 2022-03-17 16:49:06 -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
dmaclach b053a5ae11
Update partial.bzl to generate better markdown (#309) 2021-07-26 15:26:28 -04:00
Alexandre Rostovtsev 7b859037a6
to_json/to_proto methods on structs are deprecated and will be removed (#295) 2021-05-03 12:27:40 -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
Bocete 2a44ef8ec8
Add `new_sets` as a dep of `sets` bzl_library (#253)
Without this change, evaluating bzl with strict dependencies results in an error.

[`load(":new_sets.bzl", _sets = "sets")`](560d7b2359/lib/sets.bzl (L17)) results in `No such file or directory: 'third_party/bazel_skylib/lib/new_sets.bzl`
2020-07-22 08:51:32 +08:00
Andrew Z Allen d35e8d7bc6
Create Gazelle language for Starlark (#251) 2020-06-26 17:04:12 +02:00
Andrew Z Allen 3b666f525d
Address lint errors (#254) 2020-06-19 19:49:52 +02:00
Laurent Le Brun 2d0c651291 Update visibility of files (#243)
Stardoc needs access to a file (with exports_files) in order to
generate its documentation.
2020-04-02 22:20:57 +02:00
Greg dfcfe82500
Fix type parsing errors on "always true" conditions. (#239)
Specifically:

selects.config_setting_group(
    name = "always_true",
    match_any = ["//conditions:default"],
)

and

selects.config_setting_group(
    name = "always_true",
    match_all = ["//conditions:default"],
)

These should, as expected, always evaluate to True.
Their implementation had a bug that failed the build outright.
2020-03-25 14:05:24 -04:00
Thomas Van Lenten 2d620ba1f8
Fix the comment to match the code. (#238)
Looking at the impl, it only accepts sets.
2020-03-19 12:40:56 -04: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
TechSY730 3154dbbc41 Add types.is_set() to test whether an arbitrary object is a set as defined by new_sets.bzl. (#181)
* Add sets.is_set() to test whether an arbitrary object is a set.

Since using sets requires special API, it can be useful to determine
whether an object is a set so special handling can be used.
For example, if a method wants to be able to take a list or a set.
2019-09-17 10:21:44 -04:00
aiuto ab87410a8b
Use rules_pkg to make the skylib tarball for a release. (#185)
* add empty CHANGELOG.md to try to reuse bazel release.sh

* checkpoint a new distribution method

* Update CHANGELOG.

* checkpoint relnew

* get the tarball working

* fix visibilyt

* whitespace

* punctuation typos

* buildify

* linty fresh
2019-08-23 14:37:16 -04:00
Thomas Van Lenten d2cf1cc2bc
`print`->`fail` and suppress the warning in another case. (#177) 2019-07-22 13:25:00 -04:00
kwasimensah a6c72f2b39 Make config_setting_group visibility aware (#168) 2019-07-16 11:45:12 -04:00
aiuto c102f5d414 Get docs working again. (#165)
- Update to newer version of stardoc.
- Make lib/selects.bzl stardoc compatible. There must be a block description before Args:

Docs now generate with
    bazel build --incompatible_remap_main_repo docs:*

See https://github.com/bazelbuild/bazel/issues/7130 for reasons.
2019-07-02 12:35:55 -04:00
Greg 6a6a509f36 selects.bzl: Add config_setting_group for config_setting AND/OR-chaining (#89)
* Add config_setting_group for config_setting AND/OR-chaining

Implements https://github.com/bazelbuild/proposals/blob/master/designs/2018-11-09-config-setting-chaining.md.

* buildifier lint fixes

* Add tests

* Add test stub for both match_any and match_all

* Simplify the implementation and make it more correct. :)

* Fix styling issues
2019-06-05 17:39:51 -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
Thomas Van Lenten f80abf6578 Fix typo (#142) 2019-05-01 13:38:59 -04:00
Dave Lee aeefb6531a Accept kwargs in dicts.add() (#130)
Accept kwargs in dicts.add()
2019-03-20 13:08:29 -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
Tony Allevato 6741f73322 Add `types.is_depset`. (#105) 2019-02-08 18:37:26 +01:00
c-parsons 197d869482
fix various linter errors (#93) 2019-01-14 12:41:43 -05:00
Josh Morton 9948d5538b Wrap invocation of dict.items() in list(). (#91)
Some infrastructure parses bzl files as python, which fails when
dict.items() returns a special dict_items generator instead of a list in
python3.
2019-01-10 15:26:52 -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
Nathan Herring f4a2bae427 Fix Skylark analyzer warning. (#81) 2018-11-29 11:53:05 +01:00
Nathan Herring 5b8a8d3e31 Fix skylark_library deps for new_sets and unittest. (#76)
* Add dicts to new_set's dependencies.

Fixes issue 75.

* Add new_sets to deps for unittest.
2018-11-27 11:50:34 +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 9566d63ba0 Rename sets.bzl to old_sets.bzl (#70)
* Rename sets.bzl as old_setz.bzl

* Reexport old_sets.bzl in sets.bzl

* Add old_sets.bzl to :sets
2018-11-20 16:54:09 -05:00
c-parsons 58f9c41304
make sets.bzl compatible with --incompatible_depset_is_not_iterable (#71) 2018-11-20 13:19:38 -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
Thomas Van Lenten 6ad5e286cb Cache the types to avoid fetching it every time. (#64)
Along the lines of the caching done in #62
2018-11-13 00:03:11 +01:00
TechSY730 d17ca08d28 Make _precondition_only_sets_or_lists in sets.bzl not assume type() returns a string. (#62)
Such an assumption makes this check brittle in the face of potential future changes to type().
2018-11-12 19:44:29 +01:00