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

Import Bats assertions from mbland/custom-links #181

Closed
mbland opened this issue Aug 26, 2017 · 0 comments
Closed

Import Bats assertions from mbland/custom-links #181

mbland opened this issue Aug 26, 2017 · 0 comments
Assignees
Milestone

Comments

@mbland
Copy link
Owner

mbland commented Aug 26, 2017

As mentioned in mbland/custom-links#138, the run_in_background, wait_for_background_output, and stop_background_run helpers in that project's tests/scripts/serve.bats should get migrated into lib/bats/helpers.

@mbland mbland self-assigned this Aug 26, 2017
@mbland mbland modified the milestone: v1.7.0 Aug 27, 2017
mbland added a commit that referenced this issue Aug 29, 2017
This is one of the functions listed #186 as a candidate for migration
from `tests/template.bats`. I realized it would be helpful to have this
function while migrating the assertions from `tests/scripts/serve.bats`
in mbland/custom-links per #181.

This commit contains two additional changes:

It removes the `--in-process` option from `stub_program_in_path`. It
turns out I wasn't using that option anywhere, and I couldn't make any
tests fail because it didn't have an effect anyway, since the `run`
function from Bats always launches its arguments in a new subshell.

`restore_program_in_path` now strips `BATS_TEST_BINDIR` from the
beginning of `PATH`.
mbland added a commit that referenced this issue Sep 1, 2017
Also adds `create_forwarding_scripts` to create multiple forwarding
scripts in one call.

The updates to `create_forwrading_script` addresses several shortcomings
that became apparent while using it to test the new test helper
`skip_if_missing_background_utilities` that I'm adding as part of #181.

First, I needed a way to better restrict the `PATH` of the forwarded
command. Trying to set `PATH` while invoking `create_forwarding_script`
would lead to no forwarding script being created if `PATH` excluded the
directory containing the forwarded program. The new `--path` option
resolves this.

That specific change also resolved a bug where `$@` was passed to
`stub_program_in_path`, rather than just the command name argument,
causing the script to contain the arguments after the command name.

It then became apparent that the forwarding script needed to `exec` the
wrapped command. As explained in the implementation comments:

  The `exec` feature of the forwarding script is crucial, otherwise the
  parent process ID within the executed program will be set to the
  process ID of the wrapper, not the process that invoked the wrapper.

  For example, not calling `exec` confuses `bats-exec-test`, which
  invokes itself via `bats_perform_tests`. As a result, in the parent
  process, `bats_preprocess_source` creates BATS_TEST_SOURCE based on
  BATS_TMPNAME, which is based on $$; then
  `bats_evaluate_preprocessed_source` in the child process tries to
  execute BATS_TEST_SOURCE based on BATS_PARENT_TMPNAME, which is based
  on $PPID. Since they're different, Bats raises a 'No such file or
  directory' error.

  The correct thing for Bats to do is prefix its self-execution with
  `BATS_TEST_SOURCE="$BATS_TEST_SOURCE"`, but it's still good practice
  to use `exec` here, and to understand why it's important.
mbland added a commit that referenced this issue Sep 1, 2017
Closes #181. All except for `skip_if_missing_background_utilities` are
imported from mbland/custom-links, where they were used to test the
`./go serve` command.
mbland added a commit that referenced this issue Sep 1, 2017
Closes #181. All except for `skip_if_missing_background_utilities` and
`run_test_script_in_background` are imported from mbland/custom-links,
where they were used to test the `./go serve` command.
mbland referenced this issue Sep 2, 2017
lib/bats: Add background process helper functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant