vegardit / haxe-doctest

A haxelib inspired by Python's doctest command that generates unit tests based on assertions specified within the source code.

Home Page:http://vegardit.github.io/haxe-doctest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

munit should not need to be installed.

nanjizal opened this issue · comments

munit should not need to be installed but it complains if not listed as a -lib, I don't have it installed, I don't want to install it as I am fine using std or if needed fancy would explore tink.

around line 99 of DocTestGenerator needs amends not sure of detail,
but you can use #if munit

    // generate a new testMethod if required
    if (testMethodAssertions.length == MAX_ASSERTIONS_PER_TEST_METHOD ||
     Std.is(doctestAdapter, HaxeUnitDocTestAdapter) 
    #if munit
       || Std.is(doctestAdapter, MUnitDocTestAdapter) 
    #end

then at end of the file something like...

     static function getDocTestAdapter():DocTestAdapter {
        var clazz:ClassType = Context.getLocalClass().get();
        while (true) {
            if (clazz.module == "hx.doctest.DocTestRunner") return new TestrunnerDocTestAdapter();
            if (clazz.module == "haxe.unit.TestCase") return new HaxeUnitDocTestAdapter();
            if (clazz.module == "utest.Test") return new HaxeUtestDocTestAdapter(); // need this new adaptor
            #if tink_testrunner // to prevent "Type not found : tink.testrunner.Case" in TinkTestrunnerDocTestAdapter when tink_testrunner is not present
            if (clazz.module == "tink.testrunner.Suite") return new TinkTestrunnerDocTestAdapter();
            #end
            if (clazz.superClass == null) break;
            clazz = clazz.superClass.t.get();
        }

        // if no known super class was found, we expect it to be a MUnit test case
        #if munit
          return new MUnitDocTestAdapter();
        #else
          throw 'failed to find suitable TestAdapter';
          return null;
        #end
    }

I cannot reproduce this. I am using haxedoc-test without a library reference to munit for example in haxe-concurrent or haxe-strings.

Can you show my the full error including stacktrace please.

I use this code as per the documentation.

@:build(hx.doctest.DocTestGenerator.generateDocTests())

that calls

var doctestAdapter = getDocTestAdapter();

So if I don't have

haxe.unit.TestCase
tink.testrunner.Suite
utest.ITest

it defaults to try to use munit an errors because it's not testing by string it's testing by name.
you don't get the error in your projects because you have set them up with one of these.
As explained this is because I am using haxe4 and not using and compat3 stuff and need utest adaptor.

So in theory it should not get to return munit because normally it would stop before, but #if munit would be better.

I want to do testing the same way that haxe complier team do with utest so I hope your able to update I am very reluctant to look into the macro code you use well not untill got a bit further implementing hxTrueType ttf save. But do want to get back to geom but probably look to implement tests old fashion way.

Thanks for swift reply on these.

I just released haxe-doctest 1.3.0 which additionally supports utest. See https://github.com/vegardit/haxe-doctest#doctest-with-utest

Oh that's brilliant thanks 👍 🥇