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

Improve unit testing situation #12

Open
rcorre opened this issue Mar 20, 2015 · 5 comments
Open

Improve unit testing situation #12

rcorre opened this issue Mar 20, 2015 · 5 comments
Labels
Milestone

Comments

@rcorre
Copy link
Owner

rcorre commented Mar 20, 2015

Look in to using a proper unit-testing framework.
At the very least, add descriptive messages to unit-test asserts.

@rcorre rcorre added the cleanup label Mar 20, 2015
@rcorre rcorre added this to the v1.0 milestone Mar 21, 2015
@SerialVelocity
Copy link

I've started using unit_threaded after looking at them all. It requires a slight dub.json hack to make it work but I preferred its syntax over the others. Let me know which you like more :)

@rcorre
Copy link
Owner Author

rcorre commented Mar 22, 2015

I was actually looking at dtest, which is apparently a wrapper around unit_threaded that allows it to automatically find your tests.

@SerialVelocity
Copy link

Yes, I tried using that. I didn't like that I had to invoke dtest instead of overriding dub test. So, I actually use dtest inside my dub.json. It is a bit hacky but I required some fixes that aren't available in the latest unit_threaded release (or develop):

  "configurations": [
    {
      "name": "library",
    },
    {
      "name": "unittest",
      "targetType": "executable",
      "mainSourceFile": "unit_threaded_tests.d",
      "importPaths": [
        ".",
      ],
      "sourcePaths": [
        ".",
      ],
      "preGenerateCommands": [
        "cd $PACKAGE_DIR && dub run dtest --quiet -- -f unit_threaded_tests.d > /dev/null",
        "cd $PACKAGE_DIR && sed -i.bak 's/import unit_threaded.runner;/import unit_threaded.io : WriterThread; import unit_threaded.runner : runTests;/' unit_threaded_tests.d",
        "cd $PACKAGE_DIR && sed -i.bak 's/import std.stdio;/import std.stdio : writeln;/' unit_threaded_tests.d",
        "cd $PACKAGE_DIR && sed -i.bak 's/\\(int main(string\\[\\] args) {\\)/\\1 scope(exit) WriterThread.get.join();/' unit_threaded_tests.d",
      ],
      "versions": [
        "VibeCustomMain"
      ],
    },
  ],

The preGenerateCommands do the following:

  • Run dtest and generate the tests file (this is for a subproject)
  • Import the io module for unit_threaded and use scoped imports for unit_threaded.
  • Use scoped imports for std.stdio
  • Join with WriterThread on exit to fix an interaction bug between vibe.d and unit_threaded.

The scoped imports are for dscanner. I have yet to make that run through dub though (try dub fetch dscanner && dub run dscanner if you want to know why).

@rcorre
Copy link
Owner Author

rcorre commented Mar 22, 2015

Cool, thanks for posting this! I'd definitely prefer to keep using dub test than having to invoke dtest separately.

@SerialVelocity
Copy link

Note: I didn't put dub fetch dtest in there for multiple reasons:

  • It's slow
  • If you have no internet connection it breaks
  • Why try and get it over and over?

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

No branches or pull requests

2 participants