From: jenkins-bot Date: Tue, 27 Jun 2017 22:39:10 +0000 (+0000) Subject: Merge "Remove "@author Aaron Schulz" annotations" X-Git-Tag: 1.31.0-rc.0~2868 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=203cedd029e42bd3c55e50a9cff6f14373d8aa67;hp=82e2c924e473fa3b99bb8e0da71d99b70ec5ca07 Merge "Remove "@author Aaron Schulz" annotations" --- diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 0039d20632..832da4db79 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -35,15 +35,20 @@ require_once __DIR__ . '/../Maintenance.php'; */ abstract class Benchmarker extends Maintenance { protected $defaultCount = 100; + private $lang; public function __construct() { parent::__construct(); $this->addOption( 'count', 'How many times to run a benchmark', false, true ); + $this->addOption( 'verbose', 'Verbose logging of resource usage', false, false, 'v' ); } public function bench( array $benchs ) { + $this->lang = Language::factory( 'en' ); + $this->startBench(); $count = $this->getOption( 'count', $this->defaultCount ); + $verbose = $this->hasOption( 'verbose' ); foreach ( $benchs as $key => $bench ) { // Shortcut for simple functions if ( is_callable( $bench ) ) { @@ -66,6 +71,9 @@ abstract class Benchmarker extends Maintenance { $t = microtime( true ); call_user_func_array( $bench['function'], $bench['args'] ); $t = ( microtime( true ) - $t ) * 1000; + if ( $verbose ) { + $this->verboseRun( $i ); + } $times[] = $t; } @@ -104,6 +112,10 @@ abstract class Benchmarker extends Maintenance { 'median' => $median, 'mean' => $mean, 'max' => $max, + 'usage' => [ + 'mem' => memory_get_usage( true ), + 'mempeak' => memory_get_peak_usage( true ), + ], ] ); } } @@ -126,12 +138,32 @@ abstract class Benchmarker extends Maintenance { 'times', $res['count'] ); + foreach ( [ 'total', 'min', 'median', 'mean', 'max' ] as $metric ) { $ret .= sprintf( " %' 6s: %6.2fms\n", $metric, $res[$metric] ); } + + foreach ( [ + 'mem' => 'Current memory usage', + 'mempeak' => 'Peak memory usage' + ] as $key => $label ) { + $ret .= sprintf( "%' 20s: %s\n", + $label, + $this->lang->formatSize( $res['usage'][$key] ) + ); + } + $this->output( "$ret\n" ); } + + protected function verboseRun( $iteration ) { + $this->output( sprintf( "#%3d - memory: %-10s - peak: %-10s\n", + $iteration, + $this->lang->formatSize( memory_get_usage( true ) ), + $this->lang->formatSize( memory_get_peak_usage( true ) ) + ) ); + } } diff --git a/tests/phpunit/data/resourceloader/script-comment.js b/tests/phpunit/data/resourceloader/script-comment.js new file mode 100644 index 0000000000..46b60f9c01 --- /dev/null +++ b/tests/phpunit/data/resourceloader/script-comment.js @@ -0,0 +1,3 @@ +/* eslint-disable */ +mw.foo() +// mw.bar(); diff --git a/tests/phpunit/data/resourceloader/script-nosemi.js b/tests/phpunit/data/resourceloader/script-nosemi.js new file mode 100644 index 0000000000..2b1550fa9e --- /dev/null +++ b/tests/phpunit/data/resourceloader/script-nosemi.js @@ -0,0 +1,2 @@ +/* eslint-disable */ +mw.foo() diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php index 9750ea49de..ded56e9201 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php @@ -132,10 +132,30 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { */ public function testDeprecatedModules( $name, $expected ) { $modules = self::getModules(); - $rl = new ResourceLoaderFileModule( $modules[$name] ); - $rl->setName( $name ); + $module = new ResourceLoaderFileModule( $modules[$name] ); + $module->setName( $name ); $ctx = $this->getResourceLoaderContext(); - $this->assertEquals( $rl->getScript( $ctx ), $expected ); + $this->assertEquals( $module->getScript( $ctx ), $expected ); + } + + /** + * @covers ResourceLoaderFileModule::getScript + */ + public function testGetScript() { + $module = new ResourceLoaderFileModule( [ + 'localBasePath' => __DIR__ . '/../../data/resourceloader', + 'scripts' => [ 'script-nosemi.js', 'script-comment.js' ], + ] ); + $module->setName( 'testing' ); + $ctx = $this->getResourceLoaderContext(); + $this->assertEquals( + "/* eslint-disable */\nmw.foo()\n" . + "\n" . + "/* eslint-disable */\nmw.foo()\n// mw.bar();\n" . + "\n", + $module->getScript( $ctx ), + 'scripts are concatenated with a new-line' + ); } /** diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 17861d8929..6057b9710b 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -94,6 +94,52 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { ); } + public static function provideBuildContentScripts() { + return [ + [ + "mw.foo()", + "mw.foo();\n", + ], + [ + "mw.foo();", + "mw.foo();", + ], + [ + "mw.foo();\n", + "mw.foo();\n", + ], + [ + "mw.foo()\n", + "mw.foo()\n;\n", + ], + [ + "mw.foo()\n// mw.bar();", + "mw.foo()\n// mw.bar();", + ], + [ + "mw.foo()// mw.bar();", + "mw.foo()// mw.bar();", + ], + ]; + } + + /** + * @dataProvider provideBuildContentScripts + * @covers ResourceLoaderModule::buildContent + */ + public function testBuildContentScripts( $raw, $build, $message = null ) { + $context = $this->getResourceLoaderContext(); + $module = new ResourceLoaderTestModule( [ + 'script' => $raw + ] ); + $this->assertEquals( $raw, $module->getScript( $context ), 'Raw script' ); + $this->assertEquals( + [ 'scripts' => $build ], + $module->getModuleContent( $context ), + $message + ); + } + /** * @covers ResourceLoaderModule::getRelativePaths * @covers ResourceLoaderModule::expandRelativePaths