[Pkg-javascript-commits] [node-grunt-legacy-log] 01/03: Import Upstream version 1.0.0

Sruthi Chandran srud-guest at moszumanska.debian.org
Fri Nov 11 07:45:12 UTC 2016


This is an automated email from the git hooks/post-receive script.

srud-guest pushed a commit to branch master
in repository node-grunt-legacy-log.

commit 9eff3aa11389142fffed698b7dd1bf6128aeb1c0
Author: Sruthi <srud at disroot.org>
Date:   Fri Nov 11 13:05:24 2016 +0530

    Import Upstream version 1.0.0
---
 .gitignore    |   1 +
 .jshintrc     |  14 ++
 .travis.yml   |  14 ++
 CHANGELOG     |   6 +
 Gruntfile.js  |  30 ++++
 LICENSE-MIT   |  22 +++
 README.md     |   6 +
 appveyor.yml  |  28 ++++
 examples.js   |  26 +++
 index.js      | 285 ++++++++++++++++++++++++++++++++
 package.json  |  40 +++++
 test/index.js | 519 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 12 files changed, 991 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..2b7e39b
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,14 @@
+{
+  "curly": true,
+  "eqeqeq": true,
+  "immed": true,
+  "latedef": "nofunc",
+  "newcap": true,
+  "noarg": true,
+  "sub": true,
+  "undef": true,
+  "unused": true,
+  "boss": true,
+  "eqnull": true,
+  "node": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..201c484
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+sudo: false
+language: node_js
+node_js:
+  - "0.10"
+  - "0.12"
+  - "4.0"
+  - "4.1"
+  - "4.2"
+  - "5"
+  - "iojs"
+before_install:
+  - npm install -g npm
+matrix:
+  fast_finish: true
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..c4e4bb0
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,6 @@
+v1.0.0:
+  date: 2016-04-03
+  changes:
+    - Add appveyor testing
+    - Fix node.js version support
+    - Peer dependency updates
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..d7e5845
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,30 @@
+'use strict';
+
+module.exports = function(grunt) {
+
+  grunt.initConfig({
+    jshint: {
+      options: {
+        jshintrc: '.jshintrc',
+      },
+      all: ['*.js', 'test/*.js'],
+    },
+    nodeunit: {
+      util: ['test/index.js']
+    },
+    watch: {
+      all: {
+        files: ['<%= jshint.all %>'],
+        tasks: ['test'],
+      },
+    },
+  });
+
+  grunt.loadNpmTasks('grunt-contrib-jshint');
+  grunt.loadNpmTasks('grunt-contrib-nodeunit');
+  grunt.loadNpmTasks('grunt-contrib-watch');
+
+  grunt.registerTask('test', ['jshint', 'nodeunit']);
+  grunt.registerTask('default', ['test', 'watch']);
+
+};
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..1056fb5
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2014 "Cowboy" Ben Alman
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1481216
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+# grunt-legacy-log
+> The Grunt 0.4.x logger.
+
+[![Build Status](https://secure.travis-ci.org/gruntjs/grunt-legacy-log.png?branch=master)](http://travis-ci.org/gruntjs/grunt-legacy-log)
+[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
+
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..7eb2a63
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,28 @@
+# Fix line endings on Windows
+init:
+  - git config --global core.autocrlf true
+# What combinations to test
+environment:
+  matrix:
+    - nodejs_version: "0.10"
+    - nodejs_version: "0.12"
+    - nodejs_version: "4"
+platform:
+  - x86
+  - x64
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm install -g npm
+  - npm install
+test_script:
+  # Output useful info for debugging.
+  - node --version && npm --version
+  # We test multiple Windows shells because of prior stdout buffering issues
+  # filed against Grunt. https://github.com/joyent/node/issues/3584
+  - ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
+  - cmd: npm test
+build: off
+matrix:
+  fast_finish: true
+cache:
+  - node_modules -> package.json # local npm modules
diff --git a/examples.js b/examples.js
new file mode 100644
index 0000000..888ed80
--- /dev/null
+++ b/examples.js
@@ -0,0 +1,26 @@
+var Log = require('./').Log;
+
+function doThings(options) {
+  console.log();
+  console.log(options);
+  var log = new Log(options);
+  log.header("Header line.");
+  log.subhead("Subhead line.");
+  log.write("Testing").write(" 123...").writeln("done!");
+  log.write("Verbose: ").verbose.write("YES").or.write("NO").always.write(", ");
+  log.notverbose.write("NO").or.write("YES").always.writeln("!");
+  log.warn("This is a warning.");
+  log.write("Doing something...").warn();
+  log.error("This is an error.");
+  log.write("Doing something...").error();
+  log.ok("This is ok.");
+  log.write("Doing something...").ok();
+  log.errorlns("This is a very long line in errorlns that should wrap eventually, given that it is a very long line.");
+  log.oklns("This is a very long line in oklns that should wrap eventually, given that it is a very long line.");
+  log.success("This is a success message.");
+  log.fail("This is a fail message.");
+  log.debug("This is a debug message.");
+}
+
+doThings({});
+doThings({verbose: true});
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ed9b4d3
--- /dev/null
+++ b/index.js
@@ -0,0 +1,285 @@
+/*
+ * grunt
+ * http://gruntjs.com/
+ *
+ * Copyright (c) 2014 "Cowboy" Ben Alman
+ * Licensed under the MIT license.
+ * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
+ */
+
+'use strict';
+
+// Nodejs libs.
+var util = require('util');
+
+// External libs.
+var hooker = require('hooker');
+// Requiring this here modifies the String prototype!
+var colors = require('colors');
+// The upcoming lodash 2.5+ should remove the need for underscore.string.
+var _ = require('lodash');
+_.str = require('underscore.string');
+_.mixin(_.str.exports());
+// TODO: ADD CHALK
+
+var logUtils = require('grunt-legacy-log-utils');
+
+function Log(options) {
+  // This property always refers to the "base" logger.
+  this.always = this;
+  // Extend options.
+  this.options = _.extend({}, {
+    // Show colors in output?
+    color: true,
+    // Enable verbose-mode logging?
+    verbose: false,
+    // Enable debug logging statement?
+    debug: false,
+    // Where should messages be output?
+    outStream: process.stdout,
+    // NOTE: the color, verbose, debug options will be ignored if the
+    // "grunt" option is specified! See the Log.prototype.option and
+    // the Log.prototype.error methods for more info.
+    grunt: null,
+    // Where should output wrap? If null, use legacy Grunt defaults.
+    maxCols: null,
+    // Should logger start muted?
+    muted: false,
+  }, options);
+  // True once anything has actually been logged.
+  this.hasLogged = false;
+
+  // Related verbose / notverbose loggers.
+  this.verbose = new VerboseLog(this, true);
+  this.notverbose = new VerboseLog(this, false);
+  this.verbose.or = this.notverbose;
+  this.notverbose.or = this.verbose;
+
+  // Apparently, people have using grunt.log in interesting ways. Just bind
+  // all methods so that "this" is irrelevant.
+  if (this.options.grunt) {
+    _.bindAll(this);
+    _.bindAll(this.verbose);
+    _.bindAll(this.notverbose);
+  }
+}
+exports.Log = Log;
+
+// Am I doing it wrong? :P
+function VerboseLog(parentLog, verbose) {
+  // Keep track of the original, base "Log" instance.
+  this.always = parentLog;
+  // This logger is either verbose (true) or notverbose (false).
+  this._isVerbose = verbose;
+}
+util.inherits(VerboseLog, Log);
+
+VerboseLog.prototype._write = function() {
+  // Abort if not in correct verbose mode.
+  if (Boolean(this.option('verbose')) !== this._isVerbose) { return; }
+  // Otherwise... log!
+  return VerboseLog.super_.prototype._write.apply(this, arguments);
+};
+
+// Create read/write accessors that prefer the parent log's properties (in
+// the case of verbose/notverbose) to the current log's properties.
+function makeSmartAccessor(name, isOption) {
+  Object.defineProperty(Log.prototype, name, {
+    enumerable: true,
+    configurable: true,
+    get: function() {
+      return isOption ? this.always._options[name] : this.always['_' + name];
+    },
+    set: function(value) {
+      if (isOption) {
+        this.always._options[name] = value;
+      } else {
+        this.always['_' + name] = value;
+      }
+    },
+  });
+}
+makeSmartAccessor('options');
+makeSmartAccessor('hasLogged');
+makeSmartAccessor('muted', true);
+
+// Disable colors if --no-colors was passed.
+Log.prototype.initColors = function() {
+  if (this.option('no-color')) {
+    // String color getters should just return the string.
+    colors.mode = 'none';
+    // Strip colors from strings passed to console.log.
+    hooker.hook(console, 'log', function() {
+      var args = _.toArray(arguments);
+      return hooker.filter(this, args.map(function(arg) {
+        return typeof arg === 'string' ? colors.stripColors(arg) : arg;
+      }));
+    });
+  }
+};
+
+// Check for color, verbose, debug options through Grunt if specified,
+// otherwise defer to options object properties.
+Log.prototype.option = function(name) {
+  if (this.options.grunt && this.options.grunt.option) {
+    return this.options.grunt.option(name);
+  }
+  var no = name.match(/^no-(.+)$/);
+  return no ? !this.options[no[1]] : this.options[name];
+};
+
+// Parse certain markup in strings to be logged.
+Log.prototype._markup = function(str) {
+  str = str || '';
+  // Make _foo_ underline.
+  str = str.replace(/(\s|^)_(\S|\S[\s\S]+?\S)_(?=[\s,.!?]|$)/g, '$1' + '$2'.underline);
+  // Make *foo* bold.
+  str = str.replace(/(\s|^)\*(\S|\S[\s\S]+?\S)\*(?=[\s,.!?]|$)/g, '$1' + '$2'.bold);
+  return str;
+};
+
+// Similar to util.format in the standard library, however it'll always
+// convert the first argument to a string and treat it as the format string.
+Log.prototype._format = function(args) {
+  args = _.toArray(args);
+  if (args.length > 0) {
+    args[0] = String(args[0]);
+  }
+  return util.format.apply(util, args);
+};
+
+Log.prototype._write = function(msg) {
+  // Abort if muted.
+  if (this.muted) { return; }
+  // Actually write output.
+  this.hasLogged = true;
+  msg = msg || '';
+  // Users should probably use the colors-provided methods, but if they
+  // don't, this should strip extraneous color codes.
+  if (this.option('no-color')) { msg = colors.stripColors(msg); }
+  // Actually write to stdout.
+  this.options.outStream.write(this._markup(msg));
+};
+
+Log.prototype._writeln = function(msg) {
+  // Write blank line if no msg is passed in.
+  this._write((msg || '') + '\n');
+};
+
+// Write output.
+Log.prototype.write = function() {
+  this._write(this._format(arguments));
+  return this;
+};
+
+// Write a line of output.
+Log.prototype.writeln = function() {
+  this._writeln(this._format(arguments));
+  return this;
+};
+
+Log.prototype.warn = function() {
+  var msg = this._format(arguments);
+  if (arguments.length > 0) {
+    this._writeln('>> '.red + _.trim(msg).replace(/\n/g, '\n>> '.red));
+  } else {
+    this._writeln('ERROR'.red);
+  }
+  return this;
+};
+Log.prototype.error = function() {
+  if (this.options.grunt && this.options.grunt.fail) {
+    this.options.grunt.fail.errorcount++;
+  }
+  this.warn.apply(this, arguments);
+  return this;
+};
+Log.prototype.ok = function() {
+  var msg = this._format(arguments);
+  if (arguments.length > 0) {
+    this._writeln('>> '.green + _.trim(msg).replace(/\n/g, '\n>> '.green));
+  } else {
+    this._writeln('OK'.green);
+  }
+  return this;
+};
+Log.prototype.errorlns = function() {
+  var msg = this._format(arguments);
+  this.error(this.wraptext(this.options.maxCols || 77, msg));
+  return this;
+};
+Log.prototype.oklns = function() {
+  var msg = this._format(arguments);
+  this.ok(this.wraptext(this.options.maxCols || 77, msg));
+  return this;
+};
+Log.prototype.success = function() {
+  var msg = this._format(arguments);
+  this._writeln(msg.green);
+  return this;
+};
+Log.prototype.fail = function() {
+  var msg = this._format(arguments);
+  this._writeln(msg.red);
+  return this;
+};
+Log.prototype.header = function() {
+  var msg = this._format(arguments);
+  // Skip line before header, but not if header is the very first line output.
+  if (this.hasLogged) { this._writeln(); }
+  this._writeln(msg.underline);
+  return this;
+};
+Log.prototype.subhead = function() {
+  var msg = this._format(arguments);
+  // Skip line before subhead, but not if subhead is the very first line output.
+  if (this.hasLogged) { this._writeln(); }
+  this._writeln(msg.bold);
+  return this;
+};
+// For debugging.
+Log.prototype.debug = function() {
+  var msg = this._format(arguments);
+  if (this.option('debug')) {
+    this._writeln('[D] ' + msg.magenta);
+  }
+  return this;
+};
+
+// Write a line of a table.
+Log.prototype.writetableln = function(widths, texts) {
+  this._writeln(this.table(widths, texts));
+  return this;
+};
+
+// Wrap a long line of text.
+Log.prototype.writelns = function() {
+  var msg = this._format(arguments);
+  this._writeln(this.wraptext(this.options.maxCols || 80, msg));
+  return this;
+};
+
+// Display flags in verbose mode.
+Log.prototype.writeflags = function(obj, prefix) {
+  var wordlist;
+  if (Array.isArray(obj)) {
+    wordlist = this.wordlist(obj);
+  } else if (typeof obj === 'object' && obj) {
+    wordlist = this.wordlist(Object.keys(obj).map(function(key) {
+      var val = obj[key];
+      return key + (val === true ? '' : '=' + JSON.stringify(val));
+    }));
+  }
+  this._writeln((prefix || 'Flags') + ': ' + (wordlist || '(none)'.cyan));
+  return this;
+};
+
+// Add static methods.
+[
+  'wordlist',
+  'uncolor',
+  'wraptext',
+  'table',
+].forEach(function(prop) {
+  Log.prototype[prop] = exports[prop] = logUtils[prop];
+});
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..61cdea5
--- /dev/null
+++ b/package.json
@@ -0,0 +1,40 @@
+{
+  "name": "grunt-legacy-log",
+  "description": "The Grunt 0.4.x logger.",
+  "version": "1.0.0",
+  "author": "\"Cowboy\" Ben Alman (http://benalman.com/)",
+  "homepage": "http://gruntjs.com/",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/gruntjs/grunt-legacy-log.git"
+  },
+  "bugs": {
+    "url": "http://github.com/gruntjs/grunt-legacy-log/issues"
+  },
+  "license": "MIT",
+  "main": "index.js",
+  "scripts": {
+    "test": "grunt test"
+  },
+  "engines": {
+    "node": ">= 0.10.0"
+  },
+  "keywords": [
+    "grunt",
+    "legacy"
+  ],
+  "dependencies": {
+    "colors": "~1.1.2",
+    "grunt-legacy-log-utils": "~1.0.0",
+    "hooker": "~0.2.3",
+    "lodash": "~3.10.1",
+    "underscore.string": "~3.2.3"
+  },
+  "devDependencies": {
+    "grunt": "~0.4.4",
+    "grunt-cli": "~0.1.13",
+    "grunt-contrib-jshint": "~0.10.0",
+    "grunt-contrib-nodeunit": "~0.3.3",
+    "grunt-contrib-watch": "~0.6.1"
+  }
+}
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..878c270
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,519 @@
+'use strict';
+
+var legacyLog = require('../');
+var Log = legacyLog.Log;
+
+// Helper for testing stdout
+var hooker = require('hooker');
+function stdoutEqual(test, callback, expected) {
+  var actual = '';
+  // Hook process.stdout.write
+  hooker.hook(process.stdout, 'write', {
+    // This gets executed before the original process.stdout.write.
+    pre: function(result) {
+      // Concatenate uncolored result onto actual.
+      actual += result;
+      // Prevent the original process.stdout.write from executing.
+      return hooker.preempt();
+    },
+  });
+  // Execute the logging code to be tested.
+  callback();
+  // Restore process.stdout.write to its original value.
+  stdoutUnmute();
+  // Actually test the actually-logged stdout string to the expected value.
+  // test.equal(legacyLog.uncolor(actual), expected);
+  test.equal(actual, expected);
+}
+
+// Outright mute stdout.
+function stdoutMute() {
+  hooker.hook(process.stdout, 'write', {
+    pre: function() {
+      return hooker.preempt();
+    },
+  });
+}
+
+// Unmute stdout.
+function stdoutUnmute() {
+  hooker.unhook(process.stdout, 'write');
+}
+
+// Helper function: repeat('a', 3) -> 'aaa', repeat('a', 3, '-') -> 'a-a-a'
+function repeat(str, n, separator) {
+  var result = str;
+  for (var i = 1; i < n; i++) {
+    result += (separator || '') + str;
+  }
+  return result;
+}
+
+var fooBuffer = new Buffer('foo');
+
+exports['Log instance'] = {
+  setUp: function(done) {
+    this.grunt = {fail: {errorcount: 0}};
+    done();
+  },
+  'write': function(test) {
+    test.expect(4);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.write(''); }, '');
+    stdoutEqual(test, function() { log.write('foo'); }, 'foo');
+    stdoutEqual(test, function() { log.write('%s', 'foo'); }, 'foo');
+    stdoutEqual(test, function() { log.write(fooBuffer); }, 'foo');
+
+    test.done();
+  },
+  'writeln': function(test) {
+    test.expect(4);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.writeln(); }, '\n');
+    stdoutEqual(test, function() { log.writeln('foo'); }, 'foo\n');
+    stdoutEqual(test, function() { log.writeln('%s', 'foo'); }, 'foo\n');
+    stdoutEqual(test, function() { log.writeln(fooBuffer); }, 'foo\n');
+
+    test.done();
+  },
+  'warn': function(test) {
+    test.expect(5);
+    var log = new Log({grunt: this.grunt});
+
+    stdoutEqual(test, function() { log.warn(); }, 'ERROR'.red + '\n');
+    stdoutEqual(test, function() { log.warn('foo'); }, '>> '.red + 'foo\n');
+    stdoutEqual(test, function() { log.warn('%s', 'foo'); }, '>> '.red + 'foo\n');
+    stdoutEqual(test, function() { log.warn(fooBuffer); }, '>> '.red + 'foo\n');
+    test.equal(this.grunt.fail.errorcount, 0);
+
+    test.done();
+  },
+  'error': function(test) {
+    test.expect(5);
+    var log = new Log({grunt: this.grunt});
+
+    stdoutEqual(test, function() { log.error(); }, 'ERROR'.red + '\n');
+    stdoutEqual(test, function() { log.error('foo'); }, '>> '.red + 'foo\n');
+    stdoutEqual(test, function() { log.error('%s', 'foo'); }, '>> '.red + 'foo\n');
+    stdoutEqual(test, function() { log.error(fooBuffer); }, '>> '.red + 'foo\n');
+    test.equal(this.grunt.fail.errorcount, 4);
+
+    test.done();
+  },
+  'ok': function(test) {
+    test.expect(4);
+    var log = new Log({grunt: this.grunt});
+
+    stdoutEqual(test, function() { log.ok(); }, 'OK'.green + '\n');
+    stdoutEqual(test, function() { log.ok('foo'); }, '>> '.green + 'foo\n');
+    stdoutEqual(test, function() { log.ok('%s', 'foo'); }, '>> '.green + 'foo\n');
+    stdoutEqual(test, function() { log.ok(fooBuffer); }, '>> '.green + 'foo\n');
+
+    test.done();
+  },
+  'errorlns': function(test) {
+    test.expect(2);
+    var log = new Log({grunt: this.grunt});
+
+    stdoutEqual(test, function() {
+      log.errorlns(repeat('foo', 30, ' '));
+    }, '>> '.red + repeat('foo', 19, ' ') +
+      '\n>> '.red + repeat('foo', 11, ' ') + '\n');
+    test.equal(this.grunt.fail.errorcount, 1);
+
+    test.done();
+  },
+  'oklns': function(test) {
+    test.expect(1);
+    var log = new Log();
+
+    stdoutEqual(test, function() {
+      log.oklns(repeat('foo', 30, ' '));
+    }, '>> '.green + repeat('foo', 19, ' ') +
+      '\n>> '.green + repeat('foo', 11, ' ') + '\n');
+
+    test.done();
+  },
+  'success': function(test) {
+    test.expect(4);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.success(); }, ''.green + '\n');
+    stdoutEqual(test, function() { log.success('foo'); }, 'foo'.green + '\n');
+    stdoutEqual(test, function() { log.success('%s', 'foo'); }, 'foo'.green + '\n');
+    stdoutEqual(test, function() { log.success(fooBuffer); }, 'foo'.green + '\n');
+
+    test.done();
+  },
+  'fail': function(test) {
+    test.expect(4);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.fail(); }, ''.red + '\n');
+    stdoutEqual(test, function() { log.fail('foo'); }, 'foo'.red + '\n');
+    stdoutEqual(test, function() { log.fail('%s', 'foo'); }, 'foo'.red + '\n');
+    stdoutEqual(test, function() { log.fail(fooBuffer); }, 'foo'.red + '\n');
+
+    test.done();
+  },
+  'header': function(test) {
+    test.expect(5);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.header(); }, ''.underline + '\n');
+    stdoutEqual(test, function() { log.header(); }, '\n' + ''.underline + '\n');
+    stdoutEqual(test, function() { log.header('foo'); }, '\n' + 'foo'.underline + '\n');
+    stdoutEqual(test, function() { log.header('%s', 'foo'); }, '\n' + 'foo'.underline + '\n');
+    stdoutEqual(test, function() { log.header(fooBuffer); }, '\n' + 'foo'.underline + '\n');
+
+    test.done();
+  },
+  'subhead': function(test) {
+    test.expect(5);
+    var log = new Log();
+
+    stdoutEqual(test, function() { log.subhead(); }, ''.bold + '\n');
+    stdoutEqual(test, function() { log.subhead(); }, '\n' + ''.bold + '\n');
+    stdoutEqual(test, function() { log.subhead('foo'); }, '\n' + 'foo'.bold + '\n');
+    stdoutEqual(test, function() { log.subhead('%s', 'foo'); }, '\n' + 'foo'.bold + '\n');
+    stdoutEqual(test, function() { log.subhead(fooBuffer); }, '\n' + 'foo'.bold + '\n');
+
+    test.done();
+  },
+  'writetableln': function(test) {
+    test.expect(1);
+    var log = new Log();
+
+    stdoutEqual(test, function() {
+      log.writetableln([10], [repeat('foo', 10)]);
+    }, 'foofoofoof\noofoofoofo\nofoofoofoo\n');
+
+    test.done();
+  },
+  'writelns': function(test) {
+    test.expect(1);
+    var log = new Log();
+
+    stdoutEqual(test, function() {
+      log.writelns(repeat('foo', 30, ' '));
+    }, repeat('foo', 20, ' ') + '\n' +
+      repeat('foo', 10, ' ') + '\n');
+
+    test.done();
+  },
+  'writeflags': function(test) {
+    test.expect(3);
+    var log = new Log();
+
+    stdoutEqual(test, function() {
+      log.writeflags(['a', 'b']);
+    }, 'Flags: ' + 'a'.cyan + ', ' + 'b'.cyan + '\n');
+    stdoutEqual(test, function() {
+      log.writeflags(['a', 'b'], 'Prefix');
+    }, 'Prefix: ' + 'a'.cyan + ', ' + 'b'.cyan + '\n');
+    stdoutEqual(test, function() {
+      log.writeflags({a: true, b: false, c: 0, d: null}, 'Prefix');
+    }, 'Prefix: ' + 'a'.cyan + ', ' + 'b=false'.cyan + ', ' + 'c=0'.cyan + ', ' + 'd=null'.cyan + '\n');
+
+    test.done();
+  },
+  'always': function(test) {
+    test.expect(3);
+    var log = new Log();
+
+    test.strictEqual(log.always, log);
+    test.strictEqual(log.verbose.always, log);
+    test.strictEqual(log.notverbose.always, log);
+
+    test.done();
+  },
+  'or': function(test) {
+    test.expect(2);
+    var log = new Log();
+
+    test.strictEqual(log.verbose.or, log.notverbose);
+    test.strictEqual(log.notverbose.or, log.verbose);
+
+    test.done();
+  },
+  'hasLogged': function(test) {
+    // Should only be true if output has been written!
+    test.expect(24);
+    var log = new Log();
+    test.equal(log.hasLogged, false);
+    test.equal(log.verbose.hasLogged, false);
+    test.equal(log.notverbose.hasLogged, false);
+    log.write('');
+    test.equal(log.hasLogged, true);
+    test.equal(log.verbose.hasLogged, true);
+    test.equal(log.notverbose.hasLogged, true);
+
+    log = new Log({verbose: true});
+    log.verbose.write('');
+    test.equal(log.hasLogged, true);
+    test.equal(log.verbose.hasLogged, true);
+    test.equal(log.notverbose.hasLogged, true);
+
+    log = new Log();
+    log.notverbose.write('');
+    test.equal(log.hasLogged, true);
+    test.equal(log.verbose.hasLogged, true);
+    test.equal(log.notverbose.hasLogged, true);
+
+    stdoutMute();
+    log = new Log({debug: true});
+    log.debug('');
+    test.equal(log.hasLogged, true);
+    test.equal(log.verbose.hasLogged, true);
+    test.equal(log.notverbose.hasLogged, true);
+    stdoutUnmute();
+
+    // The following should be false since there's a verbose mismatch!
+    log = new Log();
+    log.verbose.write('');
+    test.equal(log.hasLogged, false);
+    test.equal(log.verbose.hasLogged, false);
+    test.equal(log.notverbose.hasLogged, false);
+
+    log = new Log({verbose: true});
+    log.notverbose.write('');
+    test.equal(log.hasLogged, false);
+    test.equal(log.verbose.hasLogged, false);
+    test.equal(log.notverbose.hasLogged, false);
+
+    // The following should be false since there's a debug mismatch!
+    log = new Log();
+    log.debug('');
+    test.equal(log.hasLogged, false);
+    test.equal(log.verbose.hasLogged, false);
+    test.equal(log.notverbose.hasLogged, false);
+
+    test.done();
+  },
+  'muted': function(test) {
+    test.expect(30);
+    var log = new Log();
+
+    test.equal(log.muted, false);
+    test.equal(log.verbose.muted, false);
+    test.equal(log.notverbose.muted, false);
+    test.equal(log.options.muted, false);
+    test.equal(log.verbose.options.muted, false);
+    test.equal(log.notverbose.options.muted, false);
+
+    log.muted = true;
+    test.equal(log.muted, true);
+    test.equal(log.verbose.muted, true);
+    test.equal(log.notverbose.muted, true);
+    test.equal(log.options.muted, true);
+    test.equal(log.verbose.options.muted, true);
+    test.equal(log.notverbose.options.muted, true);
+
+    log.muted = false;
+    test.equal(log.muted, false);
+    test.equal(log.verbose.muted, false);
+    test.equal(log.notverbose.muted, false);
+    test.equal(log.options.muted, false);
+    test.equal(log.verbose.options.muted, false);
+    test.equal(log.notverbose.options.muted, false);
+
+    log.options.muted = true;
+    test.equal(log.muted, true);
+    test.equal(log.verbose.muted, true);
+    test.equal(log.notverbose.muted, true);
+    test.equal(log.options.muted, true);
+    test.equal(log.verbose.options.muted, true);
+    test.equal(log.notverbose.options.muted, true);
+
+    log.options.muted = false;
+    test.equal(log.muted, false);
+    test.equal(log.verbose.muted, false);
+    test.equal(log.notverbose.muted, false);
+    test.equal(log.options.muted, false);
+    test.equal(log.verbose.options.muted, false);
+    test.equal(log.notverbose.options.muted, false);
+
+    test.done();
+  },
+  'verbose': function(test) {
+    test.expect(15);
+    var log = new Log();
+    log.muted = true;
+
+    // Test verbose methods to make sure they always return the verbose object.
+    test.strictEqual(log.verbose.write(''), log.verbose);
+    test.strictEqual(log.verbose.writeln(''), log.verbose);
+    test.strictEqual(log.verbose.warn(''), log.verbose);
+    test.strictEqual(log.verbose.error(''), log.verbose);
+    test.strictEqual(log.verbose.ok(''), log.verbose);
+    test.strictEqual(log.verbose.errorlns(''), log.verbose);
+    test.strictEqual(log.verbose.oklns(''), log.verbose);
+    test.strictEqual(log.verbose.success(''), log.verbose);
+    test.strictEqual(log.verbose.fail(''), log.verbose);
+    test.strictEqual(log.verbose.header(''), log.verbose);
+    test.strictEqual(log.verbose.subhead(''), log.verbose);
+    test.strictEqual(log.verbose.debug(''), log.verbose);
+    test.strictEqual(log.verbose.writetableln([]), log.verbose);
+    test.strictEqual(log.verbose.writelns(''), log.verbose);
+    test.strictEqual(log.verbose.writeflags([]), log.verbose);
+
+    test.done();
+  },
+  'notverbose': function(test) {
+    test.expect(15);
+    var log = new Log();
+    log.muted = true;
+
+    // Test notverbose methods to make sure they always return the notverbose object.
+    test.strictEqual(log.notverbose.write(''), log.notverbose);
+    test.strictEqual(log.notverbose.writeln(''), log.notverbose);
+    test.strictEqual(log.notverbose.warn(''), log.notverbose);
+    test.strictEqual(log.notverbose.error(''), log.notverbose);
+    test.strictEqual(log.notverbose.ok(''), log.notverbose);
+    test.strictEqual(log.notverbose.errorlns(''), log.notverbose);
+    test.strictEqual(log.notverbose.oklns(''), log.notverbose);
+    test.strictEqual(log.notverbose.success(''), log.notverbose);
+    test.strictEqual(log.notverbose.fail(''), log.notverbose);
+    test.strictEqual(log.notverbose.header(''), log.notverbose);
+    test.strictEqual(log.notverbose.subhead(''), log.notverbose);
+    test.strictEqual(log.notverbose.debug(''), log.notverbose);
+    test.strictEqual(log.notverbose.writetableln([]), log.notverbose);
+    test.strictEqual(log.notverbose.writelns(''), log.notverbose);
+    test.strictEqual(log.notverbose.writeflags([]), log.notverbose);
+
+    test.done();
+  },
+  'options.debug = true': function(test) {
+    test.expect(4);
+    var log = new Log({debug: true});
+
+    stdoutEqual(test, function() { log.debug(); }, '[D] ' + ''.magenta + '\n');
+    stdoutEqual(test, function() { log.debug('foo'); }, '[D] ' + 'foo'.magenta + '\n');
+    stdoutEqual(test, function() { log.debug('%s', 'foo'); }, '[D] ' + 'foo'.magenta + '\n');
+    stdoutEqual(test, function() { log.debug(fooBuffer); }, '[D] ' + 'foo'.magenta + '\n');
+
+    test.done();
+  },
+  'options.verbose = false': function(test) {
+    test.expect(7);
+    var log = new Log({verbose: false});
+
+    stdoutEqual(test, function() { log.notverbose.write('foo'); }, 'foo');
+    stdoutEqual(test, function() { log.notverbose.write('%s', 'foo'); }, 'foo');
+    stdoutEqual(test, function() { log.notverbose.write(fooBuffer); }, 'foo');
+    stdoutEqual(test, function() { log.verbose.write('foo'); }, '');
+    stdoutEqual(test, function() { log.verbose.write('%s', 'foo'); }, '');
+    stdoutEqual(test, function() { log.verbose.write(fooBuffer); }, '');
+    stdoutEqual(test, function() { log.verbose.write('a').or.write('b'); }, 'b');
+
+    test.done();
+  },
+  'options.verbose = true': function(test) {
+    test.expect(7);
+    var log = new Log({verbose: true});
+
+    stdoutEqual(test, function() { log.verbose.write('foo'); }, 'foo');
+    stdoutEqual(test, function() { log.verbose.write('%s', 'foo'); }, 'foo');
+    stdoutEqual(test, function() { log.verbose.write(fooBuffer); }, 'foo');
+    stdoutEqual(test, function() { log.notverbose.write('foo'); }, '');
+    stdoutEqual(test, function() { log.notverbose.write('%s', 'foo'); }, '');
+    stdoutEqual(test, function() { log.notverbose.write(fooBuffer); }, '');
+    stdoutEqual(test, function() { log.notverbose.write('a').or.write('b'); }, 'b');
+
+    test.done();
+  },
+  'options.debug = false': function(test) {
+    test.expect(1);
+    var log = new Log({debug: false});
+
+    stdoutEqual(test, function() { log.debug('foo'); }, '');
+
+    test.done();
+  },
+  'options.color = true': function(test) {
+    test.expect(1);
+    var log = new Log({color: true});
+
+    stdoutEqual(test, function() { log.write('foo'.blue + 'bar'.underline); }, 'foo'.blue + 'bar'.underline);
+
+    test.done();
+  },
+  'options.color = false': function(test) {
+    test.expect(1);
+    var log = new Log({color: false});
+
+    stdoutEqual(test, function() { log.write('foo'.blue + 'bar'.underline); }, 'foobar');
+
+    test.done();
+  },
+  'perma-bind this when passing grunt in (backcompat)': function(test) {
+    test.expect(43);
+    var log = new Log({grunt: this.grunt});
+    stdoutMute();
+    [
+      'write',
+      'writeln',
+      'warn',
+      'error',
+      'ok',
+      'errorlns',
+      'oklns',
+      'success',
+      'fail',
+      'header',
+      'subhead',
+      'debug',
+    ].forEach(function(method) {
+      var fn = log[method];
+      var verboseFn = log.verbose[method];
+      var notVerboseFn = log.notverbose[method];
+      test.equal(fn(), log, 'Should return log if invoked in a way where this is not log.');
+      test.equal(verboseFn(), log.verbose, 'Should return log.verbose if invoked in a way where this is not log.');
+      test.equal(notVerboseFn(), log.notverbose, 'Should return log.notverbose if invoked in a way where this is not log.');
+    });
+
+    test.doesNotThrow(function() { var fn = log.writetableln; fn([]); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.writelns; fn([]); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.writeflags; fn([]); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.wordlist; fn([]); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.uncolor; fn(''); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.wraptext; fn(1,''); }, 'Should not throw if invoked in a way where this is not log.');
+    test.doesNotThrow(function() { var fn = log.table; fn([],''); }, 'Should not throw if invoked in a way where this is not log.');
+    stdoutUnmute();
+
+    test.done();
+  },
+};
+
+exports['Helpers'] = {
+  'uncolor': function(test) {
+    test.expect(2);
+    var log = new Log();
+    test.ok(log.uncolor);
+    test.strictEqual(log.uncolor, legacyLog.uncolor);
+    test.done();
+  },
+  'wordlist': function(test) {
+    test.expect(2);
+    var log = new Log();
+    test.ok(log.wordlist);
+    test.strictEqual(log.wordlist, legacyLog.wordlist);
+    test.done();
+  },
+  'wraptext': function(test) {
+    test.expect(2);
+    var log = new Log();
+    test.ok(log.wraptext);
+    test.strictEqual(log.wraptext, legacyLog.wraptext);
+    test.done();
+  },
+  'table': function(test) {
+    test.expect(2);
+    var log = new Log();
+    test.ok(log.table);
+    test.strictEqual(log.table, legacyLog.table);
+    test.done();
+  },
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-grunt-legacy-log.git



More information about the Pkg-javascript-commits mailing list