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

Unit testing framework #176

Open
awvwgk opened this issue Sep 15, 2020 · 15 comments
Open

Unit testing framework #176

awvwgk opened this issue Sep 15, 2020 · 15 comments

Comments

@awvwgk
Copy link
Member

awvwgk commented Sep 15, 2020

I seems like we will stay with my (temporary) testing framework for now. I'm actually surprised that this idea worked out.

Nevertheless, we should discuss if there might be better alternatives or in case we want to stay with the current model, how it should behave as we implement more test suites. If we want to allow preprocessor or external (non-Fortran) dependencies we have a much wider range of testing frameworks available.

Regarding the current behaviour of the testing framework:

  • one executable for all test suites to reduce [[test]] entries in fpm.toml (related to Automatically discover executables & tests #164)
  • failing tests within a suite will not cause the testing to halt
    • better overview in a CI run about errors
    • potential for parallelisation over a test suite
  • a failing test suite will halt the testing framework
  • array constructor to register unit tests (and also test suites)
    • name and procedure pointer required (could be redundant)
    • could become fragile for very large test suites (compiler limits for array constructors)
@milancurcic
Copy link
Member

I think your framework does exactly what we need and stays out of the way. Good to have this thread open for discussion, but unless concrete problems arise I don't think we need to look further for now.

@everythingfunctional
Copy link
Member

I was going to suggest vegetables at some point, as it solves those problems. I also like it because it encourages the test descriptions to read more like a requirements specification. Your framework is actually fairly similar in terms of definition/registration of the tests, so I wasn't worried about switching, and if we do need to the transition won't seem very awkward. I also have a tool with it that automates finding all the test suites and constructing the main program.

a failing test suite will halt the testing framework

I wouldn't recommend this. It makes the output of the framework dependent on the order that it runs the tests. If the tests are independent (and they should be), the order that they're run shouldn't have any bearing on the outputs.

could become fragile for very large test suites (compiler limits for array constructors)

I've used vegetables for a project that had hundreds of tests. I don't know if fpm will have more than that, but it seems to me more likely to hit the continuation line limit before any array constructor limit (assuming there is one).

@LKedward
Copy link
Member

I'm happy with your framework since it's lightweight and easy to use as a developer.
I will echo the general sentiment here that I prefer testing to continue in the presence of test failures - this is more useful when debugging IMO.

I usually split test suites between multiple executables (hence #164) for two reasons:

  1. I can run tests in parallel trivially;
  2. Uncaught fatal errors don't stop other suites from running (granted, we shouldn't have any uncaught failures here).

With that said, I don't mind the current single-executable approach since our tests don't have any significant runtime.

@awvwgk
Copy link
Member Author

awvwgk commented Sep 16, 2020

Agreed, a failing test suite should not stop the testing. I'll address this in #177.

@arjenmarkus
Copy link
Member

arjenmarkus commented Sep 16, 2020 via email

@awvwgk
Copy link
Member Author

awvwgk commented Sep 16, 2020

In case of a test crashing we would have to run it with gdb or valgrind to debug anyway. This is not that straight-forward with fpm right now, but would probably use a similar mechanism as an external script to launch tests.

We could have something like the build-script in the library section to support more elaborated testing frameworks not only for this project but for all fpm packages:

[[test]]
name = "tester"
build-script = "collect-tests"
test-script = "run-tests"

fpm test would than call <test-script> <name> instead of just the binary.

@certik
Copy link
Member

certik commented Sep 22, 2020

I am ok with any testing framework for fpm itself. The current one is fine with me.

As long as fpm test works with any testing framework. I assume we all agree on that.

@LKedward
Copy link
Member

Related to fortran-lang/stdlib#162 and fortran-lang/stdlib#345, I am wondering whether there is motivation to extract the lightweight unit testing framework as a separate fpm package?

I liked it enough to incorporate a version of it in my fhash package, and @awvwgk is similarly maintaining a version in mctc-lib. With a cmake configuration it could also be adopted by stdlib. What do people think?

@awvwgk
Copy link
Member Author

awvwgk commented Mar 14, 2021

The mctc library already offers a CMake integration for the testing framework here to allow parallelisation over the testsuites and the individual unit tests. I think neither fpm nor stdlib want to depend on a computational chemistry IO library for testing, so spinning of a new project is the way to go.

I didn't made it its own project yet because it's an awful lot of work to maintain those and most of my use cases are covered with the mctc library now. If you are interested in co-maintaining such a project under the @fortran-lang namespace, I'll setup a project for this purpose.

@LKedward
Copy link
Member

Awesome. Yep I'm happy to help co-maintain this. Having it under the fortran-lang namespace seems like a good idea as it is used by fpm and it would hopefully encourage people to write tests for their new fpm packages!

@awvwgk
Copy link
Member Author

awvwgk commented Mar 14, 2021

I separated the testing framework from the mctc library to the repository here https://github.com/awvwgk/test-drive. It is currently very rudimentary but should already be working more or less.

@certik
Copy link
Member

certik commented Mar 16, 2021

Awesome, thanks! Fpm is under MIT license, is there a reason to change the tests to to Apache? It's probably a relatively minor issue, but I don't have that much experience with Apache. Also I feel the less licenses types we use under fortran-lang, the better.

@awvwgk
Copy link
Member Author

awvwgk commented Mar 16, 2021

I prefer Apache over other permissive licenses because it actually contains clauses that cover contributions to the project and offers some basic protection for the copyright holder, which is the basic minimum I'm expecting from a open source license I'm putting on a project I'm personally responsible for.

@certik
Copy link
Member

certik commented Mar 16, 2021

All right then. I think Apache is fine. You should also ask anybody who contributed to this code if they are ok with the license change.

@awvwgk
Copy link
Member Author

awvwgk commented Mar 16, 2021

No worries there, the relevant part in fpm is still in its original form: https://github.com/fortran-lang/fpm/blame/master/fpm/test/fpm_test/testsuite.f90, but it was not used to spin off the test-drive project in the first place anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants