'use strict';

// es-abstract's test suite requires tape >= 5.9, Debian ships tape 5.6.1.
// Provide the two assertions it uses that are missing there, copied from
// tape 5.9.0 (lib/test.js). Drop this file once node-tape is updated.

var Test = require('tape/lib/test');

if (typeof Test.prototype.assertion !== 'function') {
	Test.prototype.assertion = function assertion(fn) {
		return fn.apply(this, Array.prototype.slice.call(arguments, 1));
	};
}

if (typeof Test.prototype.captureFn !== 'function') {
	Test.prototype.captureFn = function captureFn(original) {
		if (typeof original !== 'function') {
			throw new TypeError('`original` must be a function');
		}

		var calls = [];

		var wrapped = function wrapped() {
			var args = Array.prototype.slice.call(arguments);
			var completed = false;
			try {
				var returned = original.apply(this, arguments);
				calls.push({ args: args, receiver: this, returned: returned });
				completed = true;
				return returned;
			} finally {
				if (!completed) {
					calls.push({ args: args, receiver: this, threw: true });
				}
			}
		};

		wrapped.calls = calls;

		return wrapped;
	};
}
