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

Bats ignores "dotfiles" when I tell it to look for .bats files in the current directory #863

Open
exoosh opened this issue Feb 19, 2024 · 2 comments
Labels
Component: CLI Command line flags, exit code handling, ... Component: Docs Priority: Medium Wrong or misleading documentation, broken behavior with workaround Size: Medium Changes in the same file Status: Confirmed The reproducer worked as described Type: Bug

Comments

@exoosh
Copy link

exoosh commented Feb 19, 2024

Describe the bug

It seems that bats ignores .bats files that start with a leading . when invoked to run on a directory.

To Reproduce

Steps to reproduce the behavior:

  1. Create a .foobar.bats
  2. run bats .

Expected behavior

I'd expect it to pick up the files if I only give it the directly name.

Environment (please complete the following information):

  • Bats version: Bats 1.10.0 (e823c0b)
  • operating system (including version):
    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 22.04.4 LTS
    Release:        22.04
    Codename:       jammy
    
  • bash --version:
    $ bash --version
    GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
    Copyright (C) 2020 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
  • Install method: Git from master

Additional context

I have some shell function libraries named with a leading .. Usually I will locate the "script" under test using something like this: TOTEST="${BATS_TEST_FILENAME%.*}.sh", so simply switch the script extension for .bats.

This works quite nicely, but I noticed in a helper script that I use to both lint the scripts (with ShellCheck) and invoke the test harness, bats won't pick up on .bats files starting with a leading ..

I know by convention these files are hidden and I understand if you say that's a design decision or can't be fixed because it would break existing behavior.

Just wanted to bring to your attention that this use case exists.

Thanks for bats-core!

@exoosh exoosh added Priority: NeedsTriage Issue has not been vetted yet Type: Bug labels Feb 19, 2024
@martin-schulze-vireso martin-schulze-vireso added Priority: Medium Wrong or misleading documentation, broken behavior with workaround Status: Confirmed The reproducer worked as described Component: CLI Command line flags, exit code handling, ... Size: Medium Changes in the same file and removed Priority: NeedsTriage Issue has not been vetted yet labels Feb 19, 2024
@martin-schulze-vireso
Copy link
Member

I am not sure if this was a deliberate decision. However, it seem like the behavior is inconsistent with regards to -r.

I think we need to harmonize this and probably should also document the intended behavior.

@exoosh
Copy link
Author

exoosh commented Feb 20, 2024

@martin-schulze-vireso I thought I could work around this by way of setting GLOBIGNORE=".:..", which implicitly sets dotglob. However, then ShellCheck is unhappy with me, which made me test -- to end the list of options and start the list of files (tests). Alas, this isn't supported by bats, I'll open a feature request ticket for that.

The warning I see is:

( GLOBIGNORE=".:.."; bats * )
                          ^-- SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options.

Of course it can be squelched with # shellcheck disable=SC2035 in the line preceding it, but it'd be much cooler if bats-core supported the convention of -- as terminator of options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CLI Command line flags, exit code handling, ... Component: Docs Priority: Medium Wrong or misleading documentation, broken behavior with workaround Size: Medium Changes in the same file Status: Confirmed The reproducer worked as described Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants