marklogic-community / marklogic-unit-test

Automated testing for MarkLogic
https://marklogic-community.github.io/marklogic-unit-test/
Other
13 stars 25 forks source link

Deprecate assert-throws-error() functions that accept parameters #111

Closed jamesagardner closed 1 year ago

jamesagardner commented 5 years ago

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L816

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L821

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L826

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L831

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L836

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L841

deprecate each of the functions https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L846

We should discourage an unbounded number of parameters being passed in the middle of a function with optional parameters at the end. With newer versions of MarkLogic we have support for anonymous functions, and should encourage the use of anonymous functions to invoke arbitrary code that is expected to throw an error.

Instead of passing in the method reference, and parameters as follows:

test:assert-throws-error(fn:concat#2, "this", "that")

Tests should be written to use anonymous functions to invoke the code that is expected to error:

test:assert-throws-error(function() {fn:concat("this", "that")})

Using the anonymous function has a few advantages including working around our current implementation that will break if more than 7 parameters are passed into the assert-throws-error function. It also simplifies the implementation inside test-helper by removing many overloaded functions, and relatively messy implementation at https://github.com/marklogic-community/marklogic-unit-test/blob/63a8aa4a36d1d2576469a8972ec91960b204a980/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy#L850

The existing functions should be left in place for now, and we should log an info level message letting the client know that the methods are deprecated and will be removed in a future release.

rjrudin commented 1 year ago

Tracking via DEVEXP-548.