WIP: Try using bats for running lib/tests/modules.sh#185022
Draft
infinisil wants to merge 3 commits intoNixOS:masterfrom
Draft
WIP: Try using bats for running lib/tests/modules.sh#185022infinisil wants to merge 3 commits intoNixOS:masterfrom
infinisil wants to merge 3 commits intoNixOS:masterfrom
Conversation
- init bats-assert 2.0.0 - init bats-support 0.3.0 - init bats-file 0.3.0
Adds a `bats.withLibraries (p: [ ... ])` function, which creates a
`bats` wrapper where the `BATS_LIB_PATH` environment variable contains
fallbacks for the given list of libraries.
This allows to e.g. use the `bats-assert` library (which itself requires the
`bats-support` library) with
bats.withLibraries (p: [ p.bats-support p.bats-assert ])
In a `.bats` file you can then call `bats_load_library` [1] to load the
libraries in the `setup()` function:
setup() {
bats_load_library bats-support
bats_load_library bats-assert
}
[1]: https://bats-core.readthedocs.io/en/stable/writing-tests.html?highlight=library#bats-load-library-load-system-wide-libraries
Member
|
I have a little custom code in resholve's bats helpers to write test cases like these: @test "allow (but do not parse) --fake 'source:path'" {
require <({
status 5
line 3 ends "Unexpected absolute source path."
})
} <<CASES
resholve --interpreter $INTERP --fake 'source:/not/a/real/script' < absolute_source.sh
CASES
@test "allow (*and* do not parse) --keep 'source:path' + --fake 'source:path'" {
require <({
status 0
line 2 equals "source /not/a/real/script"
})
} <<CASES
resholve --interpreter $INTERP --keep 'source:/not/a/real/script' --fake 'source:/not/a/real/script' < absolute_source.sh
resholve --interpreter $INTERP --keep '.:/not/a/real/script' --fake 'source:/not/a/real/script' < absolute_source.sh
CASES
@test "objects to unexempted tilde executable paths" {
require <({
status 7
line -1 equals "[ stdinNone ]:2: Can't resolve dynamic command"
})
} <<CASES
resholve --interpreter $INTERP < $PWD/tests/tilde_dynamic_pipeline.sh
CASESI don't see any material improvements over what you're already getting from the assert library so far (and I haven't tried to support regex), but I could look at splitting it out if it's meaningful. |
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
This is an initial attempt at using bats to run
lib/tests/modules.sh(but hopefully more in the future). By using bats we don't have to hand-roll our testing setup, it can take care of things like capturing exit status, command output, counting and reporting test failures. It also allows easily restructuring tests into a directory structure instead of having them all in a single file. It can also give names to tests.Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes