2011-06-30 23:00:13 -04:00
|
|
|
/**
|
|
|
|
* Tests the Warning prototype
|
|
|
|
*
|
2013-12-20 01:11:26 -05:00
|
|
|
* Copyright (C) 2011, 2013 Mike Gerwitz
|
2011-06-30 23:00:13 -04:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2011-06-30 23:00:13 -04:00
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
2011-06-30 23:00:13 -04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2011-06-30 23:00:13 -04:00
|
|
|
*
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-30 23:00:13 -04:00
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
*/
|
|
|
|
|
|
|
|
var common = require( './common' ),
|
|
|
|
assert = require( 'assert' ),
|
|
|
|
Warning = common.require( 'warn' ).Warning
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-07-06 17:55:40 -04:00
|
|
|
* Warning should be a subtype of Error
|
2011-06-30 23:00:13 -04:00
|
|
|
*/
|
2011-07-06 17:55:40 -04:00
|
|
|
( function testWarningIsAvailableAndHasErrorPrototype()
|
2011-06-30 23:00:13 -04:00
|
|
|
{
|
2011-07-06 17:55:40 -04:00
|
|
|
assert.ok( ( Warning( Error() ) instanceof Error ),
|
2011-06-30 23:00:13 -04:00
|
|
|
"Warning should be an instance of Error"
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
|
|
|
|
|
2011-07-06 17:55:40 -04:00
|
|
|
/**
|
|
|
|
* Make clear that we're working with a warning
|
|
|
|
*/
|
|
|
|
( function testWarningShouldAlterErrorName()
|
|
|
|
{
|
|
|
|
assert.equal( Warning( Error() ).name, 'Warning',
|
|
|
|
"Warning name should be properly set"
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
|
|
|
|
|
2011-06-30 23:00:13 -04:00
|
|
|
/**
|
|
|
|
* Just as with the other Error classes, as well as all ease.js classes, the
|
|
|
|
* 'new' keyword should be optional when instantiating the class
|
|
|
|
*/
|
|
|
|
( function testNewKeywordIsNotRequiredForInstantiation()
|
|
|
|
{
|
|
|
|
assert.ok( Warning( Error( '' ) ) instanceof Warning,
|
|
|
|
"'new' keyword should not be necessary to instantiate Warning"
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning message should be taken from the exception passed to it
|
|
|
|
*/
|
|
|
|
( function testCanWarningMessageIsSetFromWrappedException()
|
|
|
|
{
|
2011-12-04 11:38:24 -05:00
|
|
|
var err = Error( 'oshit' );
|
|
|
|
|
|
|
|
// bug in FF (tested with 8.0) where, without accessing the message property
|
|
|
|
// in this test before passing it to Warning, err.message === "" within the
|
2011-12-04 19:26:53 -05:00
|
|
|
// Warning ctor. (Assignment is to silence Closure compiler warning.)
|
|
|
|
var _ = err.message;
|
2011-12-04 11:38:24 -05:00
|
|
|
|
|
|
|
var warning = Warning( err );
|
2011-06-30 23:00:13 -04:00
|
|
|
|
|
|
|
assert.equal( warning.message, err.message,
|
|
|
|
"Warning message should be taken from wrapped exception"
|
|
|
|
);
|
2011-12-06 18:28:16 -05:00
|
|
|
|
|
|
|
// this little trick prevents the compiler from optimizing away the
|
|
|
|
// assignment, which would break the test in certain versions of FF.
|
|
|
|
return _;
|
2011-06-30 23:00:13 -04:00
|
|
|
} )();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The whole point of Warning is to wrap an exception. So, ensure that one is
|
|
|
|
* wrapped.
|
|
|
|
*/
|
|
|
|
( function testThrowsExceptionIfNoExceptionIsWrapped()
|
|
|
|
{
|
2011-12-04 19:26:53 -05:00
|
|
|
assert['throws']( function()
|
2011-06-30 23:00:13 -04:00
|
|
|
{
|
|
|
|
Warning( /* nothing provided to wrap */ );
|
|
|
|
}, TypeError, "Exception should be thrown if no exception is provided" );
|
|
|
|
|
2011-12-04 19:26:53 -05:00
|
|
|
assert['throws']( function()
|
2011-06-30 23:00:13 -04:00
|
|
|
{
|
|
|
|
Warning( 'not an exception' );
|
|
|
|
}, TypeError, "Exception should be thrown if given value is not an Error" );
|
|
|
|
} )();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We must provide access to the wrapped exception so that it can be properly
|
|
|
|
* handled. Warning is only intended to provide additional information so that
|
|
|
|
* ease.js may handle it differently than other Error instances.
|
|
|
|
*/
|
|
|
|
( function testCanRetrieveWrappedException()
|
|
|
|
{
|
|
|
|
var err = Error( 'foo' ),
|
|
|
|
warning = Warning( err );
|
|
|
|
|
|
|
|
assert.deepEqual( err, warning.getError(),
|
|
|
|
"Can retrieve wrapped exception"
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
|