<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2012, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\console\command;

use lithium\core\Libraries;
use lithium\test\Dispatcher;

/**
 * Runs a given set of tests and outputs the results.
 *
 * @see lithium\test
 */
class Test extends \lithium\console\Command {

	/**
	 * List of filters to apply before/during/after test run, separated by commas.
	 *
	 * For example:
	 * {{{
	 * lithium test lithium/tests/cases/core/ObjectTest.php --filters=Coverage
	 * lithium test lithium/tests/cases/core/ObjectTest.php --filters=Coverage,Profiler
	 * }}}
	 *
	 * @var string Name of a filter or a comma separated list of filter names. Builtin filters:
	 *      - `Affected`:   Adds tests to the run affected by the classes covered by current tests.
	 *      - `Complexity`: Calculates the cyclomatic complexity of class methods, and shows
	 *                      worst-offenders and statistics.
	 *      - `Coverage`:   Runs code coverage analysis for the executed tests.
	 *      - `Profiler`:   Tracks timing and memory usage information for each test method.
	 */
	public $filters;

	/**
	 * Format to use for rendering results. Any other format than `txt` will
	 * cause the command to enter quiet mode, surpressing headers and any other
	 * decoration.
	 *
	 * @var string Either `txt` or `json`.
	 */
	public $format = 'txt';

	/**
	 * Enable verbose output especially for the `txt` format.
	 *
	 * @var boolean
	 */
	public $verbose = false;

	/**
	 * An array of closures, mapped by type, which are set up to handle different test output
	 * formats.
	 *
	 * @var array
	 */
	protected $_handlers = array();

	/**
	 * Initializes the output handlers.
	 *
	 * @see lithium\console\command\Test::$_handlers
	 * @return void
	 */
	protected function _init() {
		parent::_init();
		$command = $this;

		$this->_handlers += array(
			'txt' => function($runner, $path) use ($command) {
				$command->header('Test');
				$command->out(null, 1);

				$command->out('{:heading}Run{:end}');

				$colorize = function($result) {
					switch (trim($result)) {
						case '.':
							return $result;
						case 'pass':
							return "{:green}{$result}{:end}";
						case 'F':
						case 'fail':
							return "{:red}{$result}{:end}";
						case 'E':
						case 'exception':
							return "{:purple}{$result}{:end}";
						case 'S':
						case 'skip':
							return "{:cyan}{$result}{:end}";
						default:
							return "{:yellow}{$result}{:end}";
					}
				};

				if ($command->verbose) {
					$reporter = function($result) use ($command, $colorize) {
						$command->out(sprintf(
							'[%s] %s::%s()',
							$colorize(sprintf('%9s', $result['result'])),
							isset($result['class']) ? $result['class'] : '??',
							isset($result['method']) ? $result['method'] : '??'
						));
					};
				} else {
					$i = 0;
					$columns = 60;

					$reporter = function($result) use ($command, &$i, $columns, $colorize) {
						$shorten = array('fail', 'skip', 'exception');

						if ($result['result'] == 'pass') {
							$symbol = '.';
						} elseif (in_array($result['result'], $shorten)) {
							$symbol = strtoupper($result['result'][0]);
						} else {
							$symbol = '?';
						}
						$command->out($colorize($symbol), false);

						$i++;
						if ($i % $columns === 0) {
							$command->out();
						}
					};
				}

				$report = $runner(compact('reporter'));

				$command->out(null, 2);
				$command->out('{:heading}Results{:end}', 0);<commit_msg>Adding line number in verbose test command output.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2012, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\console\command;

use lithium\core\Libraries;
use lithium\test\Dispatcher;

/**
 * Runs a given set of tests and outputs the results.
 *
 * @see lithium\test
 */
class Test extends \lithium\console\Command {

	/**
	 * List of filters to apply before/during/after test run, separated by commas.
	 *
	 * For example:
	 * {{{
	 * lithium test lithium/tests/cases/core/ObjectTest.php --filters=Coverage
	 * lithium test lithium/tests/cases/core/ObjectTest.php --filters=Coverage,Profiler
	 * }}}
	 *
	 * @var string Name of a filter or a comma separated list of filter names. Builtin filters:
	 *      - `Affected`:   Adds tests to the run affected by the classes covered by current tests.
	 *      - `Complexity`: Calculates the cyclomatic complexity of class methods, and shows
	 *                      worst-offenders and statistics.
	 *      - `Coverage`:   Runs code coverage analysis for the executed tests.
	 *      - `Profiler`:   Tracks timing and memory usage information for each test method.
	 */
	public $filters;

	/**
	 * Format to use for rendering results. Any other format than `txt` will
	 * cause the command to enter quiet mode, surpressing headers and any other
	 * decoration.
	 *
	 * @var string Either `txt` or `json`.
	 */
	public $format = 'txt';

	/**
	 * Enable verbose output especially for the `txt` format.
	 *
	 * @var boolean
	 */
	public $verbose = false;

	/**
	 * An array of closures, mapped by type, which are set up to handle different test output
	 * formats.
	 *
	 * @var array
	 */
	protected $_handlers = array();

	/**
	 * Initializes the output handlers.
	 *
	 * @see lithium\console\command\Test::$_handlers
	 * @return void
	 */
	protected function _init() {
		parent::_init();
		$command = $this;

		$this->_handlers += array(
			'txt' => function($runner, $path) use ($command) {
				$command->header('Test');
				$command->out(null, 1);

				$command->out('{:heading}Run{:end}');

				$colorize = function($result) {
					switch (trim($result)) {
						case '.':
							return $result;
						case 'pass':
							return "{:green}{$result}{:end}";
						case 'F':
						case 'fail':
							return "{:red}{$result}{:end}";
						case 'E':
						case 'exception':
							return "{:purple}{$result}{:end}";
						case 'S':
						case 'skip':
							return "{:cyan}{$result}{:end}";
						default:
							return "{:yellow}{$result}{:end}";
					}
				};

				if ($command->verbose) {
					$reporter = function($result) use ($command, $colorize) {
						$command->out(sprintf(
							'[%s] on line %4d in %s::%s()',
							$colorize(sprintf('%9s', $result['result'])),
							isset($result['line']) ? $result['line'] : '??',
							isset($result['class']) ? $result['class'] : '??',
							isset($result['method']) ? $result['method'] : '??'
						));
					};
				} else {
					$i = 0;
					$columns = 60;

					$reporter = function($result) use ($command, &$i, $columns, $colorize) {
						$shorten = array('fail', 'skip', 'exception');

						if ($result['result'] == 'pass') {
							$symbol = '.';
						} elseif (in_array($result['result'], $shorten)) {
							$symbol = strtoupper($result['result'][0]);
						} else {
							$symbol = '?';
						}
						$command->out($colorize($symbol), false);

						$i++;
						if ($i % $columns === 0) {
							$command->out();
						}
					};
				}

				$report = $runner(compact('reporter'));

				$command->out(null, 2);
				$command->out('{:heading}Results{:end}', 0);
{'fraction_non_alphanumeric': 0.1700487012987013, 'fraction_numerical': 0.0036525974025974025, 'mean_word_length': 2.7357251136937846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3273378', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2255, 'n_words': 632}