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

Deprecate addCaseOld(). #120

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions src/utest/Runner.hx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Runner {
}
}

#if (haxe_ver < "3.4.0" || utest_legacy)
/**
* Adds a new test case.
* @param test must be a not null object
Expand All @@ -123,20 +124,45 @@ class Runner {
#end
}

function addCaseOld(test:Dynamic, setup = "setup", teardown = "teardown", prefix = "test", ?pattern : EReg, setupAsync = "setupAsync", teardownAsync = "teardownAsync") {
if(!Reflect.isObject(test)) throw "can't add a null object as a test case";
if(!isMethod(test, setup))
setup = null;
if(!isMethod(test, setupAsync))
setupAsync = null;
if(!isMethod(test, teardown))
teardown = null;
if(!isMethod(test, teardownAsync))
teardownAsync = null;
var fields = Type.getInstanceFields(Type.getClass(test));
var className = Type.getClassName(Type.getClass(test));
for (field in fields) {
if(!isMethod(test, field)) continue;
if(!isTestFixtureName(className, field, [prefix], pattern, globalPattern)) continue;
addFixture(new TestFixture(test, field, setup, teardown, setupAsync, teardownAsync));
}
}
#else
/**
* Adds a new test case. Set `-D utest_legacy` to re-enable deprecated arguments.
* @param test must be a not null object
* @param pattern a regular expression that discriminates the names of test functions
*/
public inline function addCase(test : ITest, ?pattern : EReg) {
addITest(test, pattern);
}
#end

#if (haxe_ver >= "3.4.0")
function addITest(testCase:ITest, pattern:Null<EReg>) {
var className = Type.getClassName(Type.getClass(testCase));
if(iTestFixtures.exists(className)) {
throw 'Cannot add the same test twice.';
}
var fixtures = [];
#if as3
// AS3 can't handle the ECheckType cast. Let's dodge the issue.
var tmp:TestData.Initializer = cast testCase;
var init:TestData.InitializeUtest = tmp.__initializeUtest__();
#else
var init:TestData.InitializeUtest = (cast testCase:TestData.Initializer).__initializeUtest__();
#end
// AS3 can't handle the ECheckType cast. Let's dodge the issue.
var initializer:TestData.Initializer = cast testCase;
var init:TestData.InitializeUtest = initializer.__initializeUtest__();
for(test in init.tests) {
if(!isTestFixtureName(className, test.name, ['test', 'spec'], pattern, globalPattern)) {
continue;
Expand All @@ -157,25 +183,6 @@ class Runner {
}
#end

function addCaseOld(test:Dynamic, setup = "setup", teardown = "teardown", prefix = "test", ?pattern : EReg, setupAsync = "setupAsync", teardownAsync = "teardownAsync") {
if(!Reflect.isObject(test)) throw "can't add a null object as a test case";
if(!isMethod(test, setup))
setup = null;
if(!isMethod(test, setupAsync))
setupAsync = null;
if(!isMethod(test, teardown))
teardown = null;
if(!isMethod(test, teardownAsync))
teardownAsync = null;
var fields = Type.getInstanceFields(Type.getClass(test));
var className = Type.getClassName(Type.getClass(test));
for (field in fields) {
if(!isMethod(test, field)) continue;
if(!isTestFixtureName(className, field, [prefix], pattern, globalPattern)) continue;
addFixture(new TestFixture(test, field, setup, teardown, setupAsync, teardownAsync));
}
}

/**
* Add all test cases located in specified package `path`.
* Any module found in `path` is treated as a test case.
Expand Down