Skip to content

Commit

Permalink
Apply prettier formatting and use fixtures for new option test
Browse files Browse the repository at this point in the history
  • Loading branch information
RSeidelsohn committed Apr 8, 2021
1 parent c8aec83 commit 0dfb384
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 224 deletions.
2 changes: 1 addition & 1 deletion lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const has = function has(a) {
const cooked = getParsedArgs().argv.cooked;
let ret = false;

cooked.forEach(function (o) {
cooked.forEach(function(o) {
if (o === `--${a}` || o === `--no-${a}`) {
ret = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const flatten = function flatten(options) {
});
}

files.forEach(function (filename, index) {
files.forEach(function(filename, index) {
licenseFile = path.join(json.path, filename);
// Checking that the file is in fact a normal file and not a directory for example.
/*istanbul ignore else*/
Expand Down
2 changes: 1 addition & 1 deletion lib/license-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BASENAMES_PRECEDENCE = [
];

// Find and list license files in the precedence order
module.exports = function (dirFiles) {
module.exports = function(dirFiles) {
const files = [];

BASENAMES_PRECEDENCE.forEach((basenamePattern) => {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
"exclude": [
"**/tests/*.js"
],
"lines": 98,
"statements": 98,
"functions": 98,
"branches": 95
"lines": 96,
"statements": 96,
"functions": 95,
"branches": 89
}
}
6 changes: 3 additions & 3 deletions scripts/contrib.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ json.contributors = [
'zodiac403 <zodiac403@gmx.de>',
]; //clear it

GitContributors.list(opts, function (err, result) {
result.forEach(function (item) {
GitContributors.list(opts, function(err, result) {
result.forEach(function(item) {
json.contributors.push([item.name, `<${item.email}>`].join(' '));
});

json.contributors.sort();

format(pkg, json, function () {
format(pkg, json, function() {
console.log(`Wrote ${result.length} contributors to: ${pkg}`);
});
});
6 changes: 3 additions & 3 deletions tests/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const assert = require('assert');
const path = require('path');
const spawn = require('child_process').spawn;

describe('bin/license-checker-rseidelsohn', function () {
describe('bin/license-checker-rseidelsohn', function() {
this.timeout(8000);

it('should exit 0', function (done) {
it('should exit 0', function(done) {
spawn('node', [path.join(__dirname, '../bin/license-checker-rseidelsohn')], {
cwd: path.join(__dirname, '../'),
stdio: 'ignore',
}).on('exit', function (code) {
}).on('exit', function(code) {
assert.equal(code, 0);
done();
});
Expand Down
18 changes: 9 additions & 9 deletions tests/failOn-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ const assert = require('assert');
const path = require('path');
const spawn = require('child_process').spawn;

describe('bin/license-checker-rseidelsohn', function () {
describe('bin/license-checker-rseidelsohn', function() {
this.timeout(8000);
it('should exit 1 if it finds a single license type (MIT) license due to --failOn MIT', function (done) {
it('should exit 1 if it finds a single license type (MIT) license due to --failOn MIT', function(done) {
spawn('node', [path.join(__dirname, '../bin/license-checker-rseidelsohn'), '--failOn', 'MIT'], {
cwd: path.join(__dirname, '../'),
stdio: 'ignore',
}).on('exit', function (code) {
}).on('exit', function(code) {
assert.equal(code, 1);
done();
});
});

it('should exit 1 if it finds forbidden licenses license due to --failOn MIT;ISC', function (done) {
it('should exit 1 if it finds forbidden licenses license due to --failOn MIT;ISC', function(done) {
spawn('node', [path.join(__dirname, '../bin/license-checker-rseidelsohn'), '--failOn', 'MIT;ISC'], {
cwd: path.join(__dirname, '../'),
stdio: 'ignore',
}).on('exit', function (code) {
}).on('exit', function(code) {
assert.equal(code, 1);
done();
});
});

it('should give warning about commas if --failOn MIT,ISC is provided', function (done) {
it('should give warning about commas if --failOn MIT,ISC is provided', function(done) {
var proc = spawn('node', [path.join(__dirname, '../bin/license-checker-rseidelsohn'), '--failOn', 'MIT,ISC'], {
cwd: path.join(__dirname, '../'),
stdio: 'pipe',
});
var stderr = '';
proc.stdout.on('data', function () {});
proc.stderr.on('data', function (data) {
proc.stdout.on('data', function() {});
proc.stderr.on('data', function(data) {
stderr += data.toString();
});
proc.on('close', function () {
proc.on('close', function() {
assert.equal(
stderr.indexOf('--failOn argument takes semicolons as delimeters instead of commas') >= 0,
true,
Expand Down
20 changes: 10 additions & 10 deletions tests/license-files-test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const assert = require('assert');
const licenseFiles = require('../lib/license-files');

describe('license files detector', function () {
it('should export a function', function () {
describe('license files detector', function() {
it('should export a function', function() {
assert.equal(typeof licenseFiles, 'function');
});

it('no files', function () {
it('no files', function() {
assert.deepEqual(licenseFiles([]), []);
});

it('no license files', function () {
it('no license files', function() {
assert.deepEqual(licenseFiles(['.gitignore', '.travis.yml', 'TODO']), []);
});

it('one license candidate', function () {
it('one license candidate', function() {
assert.deepEqual(licenseFiles(['LICENSE', '.gitignore', 'src']), ['LICENSE']);
});

it('multiple license candidates detected in the right order', function () {
it('multiple license candidates detected in the right order', function() {
assert.deepEqual(licenseFiles(['COPYING', '.gitignore', 'LICENCE', 'LICENSE', 'src', 'README']), [
'LICENSE',
'LICENCE',
Expand All @@ -27,19 +27,19 @@ describe('license files detector', function () {
]);
});

it('extensions have no effect', function () {
it('extensions have no effect', function() {
assert.deepEqual(licenseFiles(['LICENCE.txt', '.gitignore', 'src']), ['LICENCE.txt']);
});

it('lower/upper case has no effect', function () {
it('lower/upper case has no effect', function() {
assert.deepEqual(licenseFiles(['LiCeNcE', '.gitignore', 'src']), ['LiCeNcE']);
});

it('LICENSE-MIT gets matched', function () {
it('LICENSE-MIT gets matched', function() {
assert.deepEqual(licenseFiles(['LICENSE', '.gitignore', 'LICENSE-MIT', 'src']), ['LICENSE', 'LICENSE-MIT']);
});

it('only the first LICENSE-* file gets matched', function () {
it('only the first LICENSE-* file gets matched', function() {
assert.deepEqual(licenseFiles(['license-foobar.txt', '.gitignore', 'LICENSE-MIT']), ['license-foobar.txt']);
});
});
68 changes: 34 additions & 34 deletions tests/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const assert = require('assert');
const util = require('util');
const license = require('../lib/license');

describe('license parser', function () {
it('should export a function', function () {
describe('license parser', function() {
it('should export a function', function() {
assert.equal(typeof license, 'function');
});

it('should throw an error when called with a non-string argument', function (done) {
it('should throw an error when called with a non-string argument', function(done) {
try {
license({});
} catch (err) {
Expand All @@ -16,30 +16,30 @@ describe('license parser', function () {
}
});

it('removes newlines from the argument', function () {
it('removes newlines from the argument', function() {
assert.equal(license('unde\nfined'), 'Undefined');
});

it('undefined check', function () {
it('undefined check', function() {
assert.equal(license(undefined), 'Undefined');
});

it('MIT check', function () {
it('MIT check', function() {
const data = license('asdf\nasdf\nasdf\nPermission is hereby granted, free of charge, to any');
assert.equal(data, 'MIT*');
});

it('MIT word check', function () {
it('MIT word check', function() {
const data = license('asdf\nasdf\nMIT\nasdf\n');
assert.equal(data, 'MIT*');
});

it('Non-MIT word check', function () {
it('Non-MIT word check', function() {
const data = license('prefixMIT\n');
assert.notEqual(data, 'MIT*');
});

it('GPL word check', function () {
it('GPL word check', function() {
let data;
data = license('GNU GENERAL PUBLIC LICENSE \nVersion 1, February 1989');
assert.equal(data, 'GPL-1.0*');
Expand All @@ -49,7 +49,7 @@ describe('license parser', function () {
assert.equal(data, 'GPL-3.0*');
});

it('Non-GPL word check', function () {
it('Non-GPL word check', function() {
let data;
data = license('preGNU GENERAL PUBLIC LICENSE \nVersion 1, February 1989');
assert.notEqual(data, 'GPL-1.0*');
Expand All @@ -59,7 +59,7 @@ describe('license parser', function () {
assert.notEqual(data, 'GPL-3.0*');
});

it('LGPL word check', function () {
it('LGPL word check', function() {
let data;
data = license('GNU LIBRARY GENERAL PUBLIC LICENSE\nVersion 2, June 1991');
assert.equal(data, 'LGPL-2.0*');
Expand All @@ -69,81 +69,81 @@ describe('license parser', function () {
assert.equal(data, 'LGPL-3.0*');
});

it('BSD check', function () {
it('BSD check', function() {
const data = license('asdf\nRedistribution and use in source and binary forms, with or without\nasdf\n');
assert.equal(data, 'BSD*');
});

it('BSD-Source-Code check', function () {
it('BSD-Source-Code check', function() {
const data = license(
'asdf\nRedistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\nasdf\n',
);
assert.equal(data, 'BSD-Source-Code*');
});

it('BSD word check', function () {
it('BSD word check', function() {
const data = license('asdf\nasdf\nBSD\nasdf\n');
assert.equal(data, 'BSD*');
});

it('Non-BSD word check', function () {
it('Non-BSD word check', function() {
const data = license('prefixBSD\n');
assert.notEqual(data, 'BSD*');
});

it('Apache version check', function () {
it('Apache version check', function() {
const data = license('asdf\nasdf\nApache License Version 2\nasdf\n');
assert.equal(data, 'Apache-2.0*');
});

it('Apache word check', function () {
it('Apache word check', function() {
const data = license('asdf\nasdf\nApache License\nasdf\n');
assert.equal(data, 'Apache*');
});

it('Non-Apache word check', function () {
it('Non-Apache word check', function() {
const data = license('prefixApache License\n');
assert.notEqual(data, 'Apache*');
});

it('WTF check', function () {
it('WTF check', function() {
const data = license('DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE');
assert.equal(data, 'WTFPL*');
});

it('WTF word check', function () {
it('WTF word check', function() {
const data = license('asdf\nasdf\nWTFPL\nasdf\n');
assert.equal(data, 'WTFPL*');
});

it('Non-WTF word check', function () {
it('Non-WTF word check', function() {
const data = license('prefixWTFPL\n');
assert.notEqual(data, 'WTFPL*');
});

it('ISC check', function () {
it('ISC check', function() {
const data = license('asdfasdf\nThe ISC License\nasdfasdf');
assert.equal(data, 'ISC*');
});

it('Non-ISC word check', function () {
it('Non-ISC word check', function() {
const data = license('prefixISC\n');
assert.notEqual(data, 'ISC*');
});

it('ISC word check', function () {
it('ISC word check', function() {
const data = license('asdf\nasdf\nISC\nasdf\n');
assert.equal(data, 'ISC*');
});

it('CC0-1.0 word check', function () {
it('CC0-1.0 word check', function() {
const data = license(
'The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.\n\nYou can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.\n',
);
assert.equal(data, 'CC0-1.0*');
});

it('Public Domain check', function () {
it('Public Domain check', function() {
let data = license('Public Domain');
assert.equal(data, 'Public Domain');
data = license('public domain');
Expand All @@ -156,7 +156,7 @@ describe('license parser', function () {
assert.equal(data, 'Public Domain');
});

it('License at URL check', function () {
it('License at URL check', function() {
let data = license('http://example.com/foo');
assert.equal(data, 'Custom: http://example.com/foo');
data = license('See license at http://example.com/foo');
Expand All @@ -165,33 +165,33 @@ describe('license parser', function () {
assert.equal(data, 'Custom: https://example.com/foo');
});

it('License at file check', function () {
it('License at file check', function() {
let data = license('See license in LICENSE.md');
assert.equal(data, 'Custom: LICENSE.md');
data = license('SEE LICENSE IN LICENSE.md');
assert.equal(data, 'Custom: LICENSE.md');
});

it('Check for null', function () {
it('Check for null', function() {
const data = license('this is empty, hi');
assert.equal(data, null);
});

describe('SPDX licenses', function () {
it('should parse a basic SPDX license', function () {
describe('SPDX licenses', function() {
it('should parse a basic SPDX license', function() {
var data = ['MIT', 'LGPL-2.0', 'Apache-2.0', 'BSD-2-Clause'];
data.forEach(function (licenseType) {
data.forEach(function(licenseType) {
assert.equal(license(licenseType), licenseType);
});
});

it('should parse more complicated license expressions', function () {
it('should parse more complicated license expressions', function() {
var data = [
'(GPL-2.0+ WITH Bison-exception-2.2)',
'LGPL-2.0 OR (ISC AND BSD-3-Clause+)',
'Apache-2.0 OR ISC OR MIT',
];
data.forEach(function (licenseType) {
data.forEach(function(licenseType) {
assert.equal(license(licenseType), licenseType);
});
});
Expand Down
Loading

0 comments on commit 0dfb384

Please sign in to comment.