co-log / co-log-core

🌽 Core types and functions that power the Haskell `co-log` implementation
Mozilla Public License 2.0
17 stars 6 forks source link

[RFC] Laws property-based tests for `LogAction` #2

Open chshersh opened 5 years ago

chshersh commented 5 years ago

It would be really nice to have tests for the logging functionality, especially property-based testing. However, it's not really clear how to test it. It would be really nice though to have property-based tests for laws for every data type. However, in order to do this, we need to implement the following two pieces:

Question 1 is still open. For Question 2: instead of comparing LogActions we can compare results of PureLogger.

We have doctest for unit testing, so this should be enough in terms of unit tests (though, more functions always can be covered with doctest). But having property-based tests for laws would be really good.

Any thoughts are appreciated!

chshersh commented 5 years ago

Nice and convenient solution for Question 2: implement the following orphan instance in the test modules

instance (Eq msg, m ~ PureLogger msg) => Eq (LogAction m msg)

With this instance it will be very easy to compare two LogActions.

In order to test we also need to implement Show instance. We can use the same approach:

instance (Show msg, m ~ PureLogger msg) => Show (LogAction m msg)

This instance will run PureLogger and show all messages as a list.