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

Runs shell unit test frameworks (bats, shunit2, etc.) #297

Open
andychu opened this issue May 6, 2019 · 10 comments
Open

Runs shell unit test frameworks (bats, shunit2, etc.) #297

andychu opened this issue May 6, 2019 · 10 comments

Comments

@andychu
Copy link
Contributor

andychu commented May 6, 2019

https://github.com/bats-core/bats-core/tree/master/libexec/bats-core

It appears to be pretty commonly used:

https://github.com/bats-core/bats-core/wiki/Projects-Using-Bats

Someone told me a basic example worked, but I also noticed that the code uses printf -v, so it must not work entirely.

Note that bats changed maintainers sometime in 2016:

sstephenson/bats#150 (comment)

@andychu
Copy link
Contributor Author

andychu commented May 6, 2019

This would be a great issue for someone who uses bats! Tell me what goes wrong :)

The underlying motivation is that I want OSH to have some kind of testing story, and it's good to be familiar with what people already use. I haven't used bats myself though!

andychu pushed a commit that referenced this issue May 15, 2019
I used the OSH style, with:

- 2 lexer modes (PrintfOuter and PrintfPercent)
- ASDL schema
- Recursive descent parser
- Extra validity checks on top of the grammar.
- span IDs to report fine-grained location info.

Addresses issue #297 (bats).  I've seen a bunch of other code which uses
it as well.
@andychu
Copy link
Contributor Author

andychu commented Feb 11, 2021

more feedback about bats here:

https://lobste.rs/s/jrzobc/better_bashing_through_technology#c_rtyj0d

Idea: we could parse bats literally with

shopt --set oil:basic
shopt --unset parse_at {
   @test "foo" {
     echo hi
   }
}

shopt --unset parse_at {
  source mytest.sh
}

Or just have people change it to

%test "foo" { 
  echo hi
}

could be .test, +test, ^test, etc. I guess the thing to do would be to patch bats to allow %test in addition to @test ... hm.

Yeah it would be a one character change here: https://github.com/bats-core/bats-core/blob/master/libexec/bats-core/bats#L74

used here:

https://github.com/bats-core/bats-core/blob/master/libexec/bats-core/bats-preprocess

@andychu
Copy link
Contributor Author

andychu commented Mar 2, 2021

Many more test frameworks listed here: https://news.ycombinator.com/item?id=26314160

  • shunit2, etc.
  • shellspec, which we already run

@andychu andychu changed the title Runs the bats test framework Runs shell unit test frameworks (bats, shunit2, etc.) Mar 2, 2021
@andychu
Copy link
Contributor Author

andychu commented Mar 2, 2021

This is important because running unit tests could be the first thing that users do to port!

@andychu
Copy link
Contributor Author

andychu commented Mar 3, 2021

Many examples of bats here: https://github.com/dolthub/dolt/tree/master/bats

However they don't appear to have a continuous build to verify it? Or at least no badge

@andychu
Copy link
Contributor Author

andychu commented May 30, 2022

Nice article that compares ShellSpec, BATS, and shUnit2

https://lobste.rs/s/2soumt/writing_unit_tests_mocks_for_unix_shells

I think the summary is that

  • ShellSpec has a DSL they didn't like
  • BATS not compatible with busybox ash?
  • shUnit2 is good

@andychu
Copy link
Contributor Author

andychu commented May 30, 2022

Note that bats uses export -f, so we're not likely to run it soon

https://lobste.rs/s/2soumt/writing_unit_tests_mocks_for_unix_shells

@bar-g
Copy link
Contributor

bar-g commented Oct 25, 2022

Um, since existing testing frameworks don't seem to be readily supported, how would you imagine/picture/sketch a good testing practice when using the oil language?

It could be quite useful to devise a plan quite early on, to support pioneer users in staying on top of changes, while the oil language is still undergoing considerable stabilizing and debugging phase.

One pattern that stuck out to me as mixing and matching quite well from some quick tests (within a single source file) up to a large testing suite's directory tree (with execution concurrency and process isolation) was the way Nim does it: https://nim-lang.github.io/Nim/unittest.html

The test file example there even seemed to remember me of hay in some way... but of course, nim is still missing the direct "command language" of a shell, even though nim is itself already written in nim, and compiles to C, C++, and more. It even supports being compiled into a nim-script run-time interpreter.

@andychu
Copy link
Contributor Author

andychu commented Nov 6, 2022

Sorry for the delay ... I'm sort of torn between writing a new test framework and running old ones.

A barrier to this is that I don't use any of these test frameworks :-P

Oil itself has a lot of shell tests, and we can definitely use a better shell to write those !


I think this work will have to come after argparse

That is a similar problem in that Oil language features are necessary to support a rich interface

i.e. we can either write arg parsers and test frameworks in Oil, or in the meta-language Python

So that is probably the first thing to work out

@bar-g
Copy link
Contributor

bar-g commented Dec 3, 2022

(Thanks, as you know I try to check in here from time to time, but can't on on all news and discussions.)

torn between writing a new test framework and running old ones.

Ok, but with hay being a thing now (is it better to say hay-markup?, hay-config/stanzas? or hay-??? to steer clear from referring to a pile of straws?) , now i don't see any old framework could usefully support hay, not even just for sample data. And hay seems so useful in writing tests even beyond just "fixtures": https://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures

So I'd guess it may inevitably end up needing some own oil testing conventions and hooks similar to https://nim-lang.github.io/Nim/unittest.html

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

2 participants