There must be module with test assertions in Phobos
Atila Neves
atila.neves at gmail.com
Fri Apr 7 12:41:08 UTC 2023
On Thursday, 30 March 2023 at 17:01:26 UTC, Dmytro Katyukha wrote:
> But, this feature is not convenient/usable without standard set
> of `assert*` methods, that could display human-readable output
> in case of error (what value expected, and what value we got).
> Because of absense of such expected functionality, there are
> some set of third-party libraries that implement good and
> readable assertions. But, most popular assertion libraries
> depend on
> [unit-threaded](https://code.dlang.org/packages/unit-threaded)
> that is large test runner.
You can depend on only the assertions dub subpackage, which is
tiny, and then use the standard runner from druntime.
> And it is strange, when you try to add small and simple library
> to dependencies of your project, but it brings whole
> unit-threaded package to your project.
That's a dub bug. If a project lists a dependency only in the
unittest configuration, it adds it to the transitive list of
dependencies, which is obviously nonsense.
> And i think, in significant amount of cases, this dependency is
> added just because standard set of asserts absent in standard
> library.
And running in threads, and running specific tests, and...
> I think, for small libraries there is no sense to depend on
> large test runner. Ususally it is enough to use standard test
> runner.
To each their own, I'd use a "proper" library every time because
of the developer experience.
> Just take a look at python's assertions from standard library
> [unittest](https://docs.python.org/3/library/unittest.html#assert-methods)
None of those are needed if using pytest, which I'd recommend
anyone writing Python code to do. One uses the standard Python
`assert` and it prints error messages that make sense. It's
magic, and it's magic I'd want for D.
> I think, implementation of this list of asserts in the Phobos
> will allow users to start use unittest much easier.
Nearly every test assertion is of equality. It's nice to have the
others when needed, but they're not a good 99.9% of the time.
> Also, the question to authors of assert libraries (like
> [unit-threaded:assertions](https://code.dlang.org/packages/unit-threaded%3Aassertions), [dshould](https://code.dlang.org/packages/dshould), etc): what do you think about contributing assertions to Phobos?
It's definitely an idea.
More information about the Digitalmars-d
mailing list