Skip to content

Sort out test suite#314

Merged
Bodigrim merged 6 commits intohaskell:masterfrom
Bodigrim:tasty
Mar 13, 2021
Merged

Sort out test suite#314
Bodigrim merged 6 commits intohaskell:masterfrom
Bodigrim:tasty

Conversation

@Bodigrim
Copy link
Copy Markdown
Contributor

Current structure of text repo is more complicated than I would like it to be. There are four separate packages: text itself, plus text-tests and th-tests, plus benchmarks.

The reason to have tests as separate packages is that they depend on test-framework, which itself depends on text. Moreover, just separating tests is not sufficient, because any change to text would cause rebuilding test-framework, test-framework-quickcheck2, test-framework-hunit, regex-posix, regex-base, xml, before being actually able to build and run the test suite. This is a very long feedback loop, so a hack is employed: instead of depending on a local package text, the test suite just lists all text modules as its own, adding ../src to hs-source-dirs.

This hack allows to avoid rebuilding intermediate packages, but has its own drawbacks such as rebuilding the same source module twice (because it is listed under two unrelated components). More importantly, this, strictly speaking, does not necessarily test text package as it is presented to users, with all its flags and ghc-options, but rather tests its source modules bundled independently, which are not warranted in sync.

Further, th-tests are a separate package, which depends on text package indeed, probably because of Template Haskell stage restrictions (?). It means that it rebuilds for ages despite all efforts put into text-tests.

Bottom line is that

  • we must update and keep in sync four cabal files,
  • we need to list a ton of files under extra-source-files,
  • coverage report does not really work,
  • running all tests is painfully slow.

This PR:

  • Replaces test-framework with tasty, which is its more modern counterpart.
  • Since tasty does not depend on text, a hack with hs-source-dirs: ../src can be abandoned without causing excessive rebuilds.
  • Consequently, there is no reason to keep two separate test suites. They can be merged, saving linking time and bookkeeping.
  • We can actually immerse our test suite into the main package. Minus two packages, simpler setup for everyone.

Areas of improvement:

  • Benchmarks stopped to build with GHC 7.10 because of the choice of semigroups flags.
  • It would be nice to build text with -fdeveloper on CI, but it breaks benchmarks.

I'll address these drawbacks in an upcoming PR, improving our situation with benchmarks in the same fashion as this PR sorts out tests, but I hope they are acceptable in the meantime.

@Lysxia
Copy link
Copy Markdown
Contributor

Lysxia commented Mar 10, 2021

Nice work!

We can actually immerse our test suite into the main package.

I'm a little worried about that. The main reason for merging seems to be that the circular dependency is gone with the move to tasty, but that seems a very brittle assumption considering how general-purpose text aims to be.

Is cabal able to resolve dependencies at the level of components within packages?

@parsonsmatt
Copy link
Copy Markdown

Further, th-tests are a separate package, which depends on text package indeed, probably because of Template Haskell stage restrictions (?). It means that it rebuilds for ages despite all efforts put into text-tests.

I don't think this is the case - the stage restrictions operate on a per-module basis, not per-package. The persistent package also separates out the Template Haskell into a separate package, and I was told that it was from a desire to not depend on template-haskell as a necessary part of the package. So that may be a similar factor here? I'm planning on merging persitent-template back into persistent at some point, so I'd be tentatively in favor of merging th stuff into a logically reasonable place.

Copy link
Copy Markdown

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

i love too see it

build-type: Simple
tested-with: GHC==9.0.1,
GHC==8.10.4, GHC==8.8.4, GHC==8.6.5, GHC==8.4.4,
GHC==8.2.2, GHC==8.0.2, GHC==7.10.3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent to restore this tested-with clause? Or are we dropping 7.10.3 support?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the bottom of #314 (comment)

This (temporarily) drops support of GHC 7.10 for benchmarks only. The text package itself still supports GHCs back to 7.0.

As @chessai pointed below, it could be a good idea to drop support of obsolete versions of GHC, but this is, strictly speaking, a separate matter, and not a decision I'm implementing in this PR.

(TA.length originalArr)
(TA.length newArr)
(I# (sizeofByteArray# (TA.aBA originalArr)))
(I# (sizeofByteArray# (TA.aBA newArr)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't appear to be related to a test-framework => tasty change. I'm curious why it's done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!

TA.length is defined only when the package is built in developer mode:

#if defined(ASSERTS)
, length
#endif

The existing test suite lists Data.Test.Array as its own module and thus can enforce -DASSERTS irrespective to actual developer flag:

cpp-options:
-DASSERTS -DTEST_SUITE

Since now the test suite depends on a proper text package, it lost its ability to enforce -DASSERTS on its modules, and now this is guided by developer flag only. In order to compile tests when this flag is not enabled, I had to avoid TA.length and replace it with sizeOfByteArray#.

It would be nice to put constraint: text +developer into cabal.project, so that all developers (and CI) have it enabled by default. Unfortunately, such configuration breaks benchmarks. As mentioned at the bottom of #314 (comment), I'll fix this in an upcoming PR.

@chessai
Copy link
Copy Markdown
Member

chessai commented Mar 10, 2021 via email

@Bodigrim
Copy link
Copy Markdown
Contributor Author

The persistent package also separates out the Template Haskell into a separate package, and I was told that it was from a desire to not depend on template-haskell as a necessary part of the package. So that may be a similar factor here?

I don't think so, text library itself already depends on template-haskell:

text/text.cabal

Line 168 in 6d8ae4d

template-haskell >= 2.5 && < 2.18

@Bodigrim
Copy link
Copy Markdown
Contributor Author

I'm a little worried about that. The main reason for merging seems to be that the circular dependency is gone with the move to tasty, but that seems a very brittle assumption considering how general-purpose text aims to be.

@Lysxia I understand your worries, but I do not expect tasty to acquire more dependencies overnight, and we can stick to older versions if needed. In my experience having tests as a part of the main package is a nice quality-of-life improvement, and we use the same approach in bytestring and unix, which are deeper in a dependency graph than text. In the worst case scenario we can always revert to separate packages in future.

Comment thread tests/Makefile
Copy link
Copy Markdown
Contributor

@Lysxia Lysxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (just removing cruft and switching to tasty)

@Bodigrim
Copy link
Copy Markdown
Contributor Author

CC @tathougies (GitHub still resists to adding you as reviewer).

Unless there are further comments, I'll merge this tomorrow.

@Bodigrim Bodigrim merged commit b03dfcc into haskell:master Mar 13, 2021
@Bodigrim Bodigrim deleted the tasty branch March 13, 2021 20:11
@Bodigrim Bodigrim mentioned this pull request Mar 13, 2021
@Lysxia Lysxia mentioned this pull request Mar 20, 2021
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

Successfully merging this pull request may close these issues.

4 participants