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

Use savePost in golden tests #20

Closed
Minoru opened this issue Jul 28, 2020 · 3 comments
Closed

Use savePost in golden tests #20

Minoru opened this issue Jul 28, 2020 · 3 comments

Comments

@Minoru
Copy link
Owner

Minoru commented Jul 28, 2020

I wrote golden tests for Hakyll.Convert.Blogger.readPosts and Wordpress.readPosts. They rely on a Show instance for types that represent a post. The default implementation prints everything out in a single line, so when a test fails, it's quite hard to see what exactly the difference is.

Furthermore, Wordpress posts are represented by a type defined in an external library. Depending on its Show instance for testing is probably a bad idea.

These tests should be rewritten with savePost, which is our function. That will lean them towards integration testing, which is fine. We can then use tasty-mgolden to provide us with nice diffs on test failures.

Blocked on #19.

@Minoru
Copy link
Owner Author

Minoru commented Nov 6, 2020

tasty-mgolden is absent from LTS-6.9 that we currently use. If we add it as an extra-package, we run into problems with dependencies:

In the dependencies for tasty-mgolden-0.0.2:
    Diff-0.3.2 from stack configuration does not match ==0.3.4 || ==0.4.*  (latest matching version is 0.4.0)
    ansi-terminal-0.6.2.3 from stack configuration does not match >=0.9 && <0.11  (latest matching version is 0.10.3)
    base-4.8.2.0 from stack configuration does not match >=4.12 && <=4.15  (latest matching version is 4.14.0.0)
    filepath-1.4.0.0 from stack configuration does not match >=1.4.2 && <1.5  (latest matching version is 1.4.2.1)
    tasty-0.11.0.3 from stack configuration does not match >=1.3.1 && <1.4  (latest matching version is 1.3.1)
needed due to hakyll-convert-0.2.0.0 -> tasty-mgolden-0.0.2

Let's postpone migrating to tasty-mgolden, then.

@Minoru
Copy link
Owner Author

Minoru commented Nov 6, 2020

Actually, this is impossible to implement, since Blogger.readPosts and Wordpress.readPosts don't return DistilledPost that IO.savePost expects. We could get a DistilledPost by testing mapM Blogger.distill $ Blogger.readPosts, but that is more like integration testing than unit testing; I don't want that.

Let's close this for now. If dependence on external types cause us too much grief, we can revisit this issue.

@Minoru Minoru closed this as completed Nov 6, 2020
@Minoru
Copy link
Owner Author

Minoru commented Nov 7, 2020

I'm currently working on #15, and after moving to a new version, golden tests for Wordpress no longer pass since the internal representation of external types changed. This made me realize that my above comment draws a false dichotomy: we can test both readPosts and (mapM (savePost . distill)) . readPosts! The former will check our public API, and the latter will ensure that we don't break the functionality of the library.

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

1 participant