Commit bbbd1502 authored by epriestley's avatar epriestley

(stable) Promote 2019 Week 21

parents 26452002 7329bc7c
......@@ -75,8 +75,8 @@ abstract class ArcanistLinterTestCase extends PhutilTestCase {
$config,
array(
'config' => 'optional map<string, wild>',
'path' => 'optional string',
'mode' => 'optional string',
'path' => 'optional string',
'stopped' => 'optional bool',
));
......@@ -171,81 +171,131 @@ abstract class ArcanistLinterTestCase extends PhutilTestCase {
$this->compareTransform($xform, $after_lint);
}
private function compareLint($file, $expect, ArcanistLintResult $result) {
$seen = array();
$raised = array();
$message_map = array();
foreach ($result->getMessages() as $message) {
$sev = $message->getSeverity();
$line = $message->getLine();
$char = $message->getChar();
$code = $message->getCode();
$name = $message->getName();
$message_key = $sev.':'.$line.':'.$char;
$message_map[$message_key] = $message;
$seen[] = $message_key;
$raised[] = sprintf(
' %s: %s %s',
pht('%s at line %d, char %d', $sev, $line, $char),
$code,
$name);
}
private function compareLint($file, $expect, ArcanistLintResult $results) {
$expected_results = new ArcanistLintResult();
$expect = trim($expect);
if ($expect) {
$expect = explode("\n", $expect);
} else {
$expect = array();
}
foreach ($expect as $key => $expected) {
$expect[$key] = head(explode(' ', $expected));
}
$expect = array_fill_keys($expect, true);
$seen = array_fill_keys($seen, true);
foreach ($expect as $result) {
$parts = explode(':', $result);
$message = new ArcanistLintMessage();
$severity = idx($parts, 0);
$line = idx($parts, 1);
$char = idx($parts, 2);
$code = idx($parts, 3);
if ($severity !== null) {
$message->setSeverity($severity);
}
if ($line !== null) {
$message->setLine($line);
}
if ($char !== null) {
$message->setChar($char);
}
if ($code !== null) {
$message->setCode($code);
}
if (!$raised) {
$raised = array(pht('No messages.'));
$expected_results->addMessage($message);
}
$raised = sprintf(
"%s:\n%s",
pht('Actually raised'),
implode("\n", $raised));
foreach (array_diff_key($expect, $seen) as $missing => $ignored) {
$missing = explode(':', $missing);
$sev = array_shift($missing);
$pos = $missing;
$missing = array();
$surprising = $results->getMessages();
$this->assertFailure(
pht(
"In '%s', expected lint to raise %s on line %d at char %d, ".
"but no %s was raised. %s",
$file,
$sev,
idx($pos, 0),
idx($pos, 1),
$sev,
$raised));
// TODO: Make this more efficient.
foreach ($expected_results->getMessages() as $expected_message) {
$found = false;
foreach ($results->getMessages() as $ii => $actual_message) {
if (!self::compareLintMessageProperty(
$expected_message->getSeverity(),
$actual_message->getSeverity())) {
continue;
}
if (!self::compareLintMessageProperty(
$expected_message->getLine(),
$actual_message->getLine())) {
continue;
}
if (!self::compareLintMessageProperty(
$expected_message->getChar(),
$actual_message->getChar())) {
continue;
}
if (!self::compareLintMessageProperty(
$expected_message->getCode(),
$actual_message->getCode())) {
continue;
}
$found = true;
unset($surprising[$ii]);
}
if (!$found) {
$missing[] = $expected_message;
}
}
foreach (array_diff_key($seen, $expect) as $surprising => $ignored) {
$message = $message_map[$surprising];
$message_info = $message->getDescription();
if ($missing || $surprising) {
$expected = pht('EXPECTED MESSAGES');
if ($missing) {
foreach ($missing as $message) {
$expected .= sprintf(
"\n %s: %s %s",
pht(
'%s at line %d, char %d',
$message->getSeverity(),
$message->getLine(),
$message->getChar()),
$message->getCode(),
$message->getName());
}
} else {
$expected .= "\n ".pht('No messages');
}
$actual = pht('UNEXPECTED MESSAGES');
if ($surprising) {
foreach ($surprising as $message) {
$actual .= sprintf(
"\n %s: %s %s",
pht(
'%s at line %d, char %d',
$message->getSeverity(),
$message->getLine(),
$message->getChar()),
$message->getCode(),
$message->getName());
}
} else {
$actual .= "\n ".pht('No messages');
}
list($sev, $line, $char) = explode(':', $surprising);
$this->assertFailure(
sprintf(
"%s:\n\n%s\n\n%s",
pht(
"In '%s', lint raised %s on line %d at char %d, ".
"but nothing was expected",
$file,
$sev,
$line,
$char),
$message_info,
$raised));
"%s\n\n%s\n\n%s",
pht("Lint failed for '%s'.", $file),
$expected,
$actual));
}
}
......@@ -259,4 +309,18 @@ abstract class ArcanistLinterTestCase extends PhutilTestCase {
pht('File as patched by lint did not match the expected patched file.'));
}
/**
* Compare properties of @{class:ArcanistLintMessage} instances.
*
* The expectation is that if one (or both) of the properties is null, then
* we don't care about its value.
*
* @param wild
* @param wild
* @return bool
*/
private static function compareLintMessageProperty($x, $y) {
return $x === null || $y === null || $x === $y;
}
}
~~~~~~~~~~
warning::
warning:0:0:CHMOD1:Invalid Executable
~~~~~~~~~~
~~~~~~~~~~
{"mode": "0755"}
~~~~~~~~~~
error::
error:0:0:NAME1:Bad Filename
~~~~~~~~~~
~~~~~~~~~~
{"path": "bad@filename"}
......@@ -3,5 +3,5 @@ x = 'y'
def hello():
return foo
~~~~~~~~~~
error:3:1
error:4:12
error:3:1:E302
error:4:12:F821
......@@ -2,5 +2,5 @@ var args = {};
args['foo'] = 'bar';
args['bar'] = 'baz';
~~~~~~~~~~
warning:2:5
warning:3:5
warning:2:5:W069
warning:3:5:W069
......@@ -3,4 +3,4 @@ if (foo = 'bar') {
return true;
}
~~~~~~~~~~
warning:2:16
warning:2:16:W084
......@@ -7,6 +7,6 @@ function f() {
{
~~~~~~~~~~
warning:3:8
error:7:1
error:9:1
warning:3:8:W033
error:7:1:E019
error:9:1:E041
console.log('foobar')
~~~~~~~~~~
warning:1:22
warning:1:22:W033
/* jshint maxerr: 1 */
console.log('foobar')
~~~~~~~~~~
disabled:2:22
warning:2:22
disabled:2:22:E043
warning:2:22:W033
......@@ -2,4 +2,4 @@ function main() {
return 'Hello, World!';
};
~~~~~~~~~~
warning:3:2
warning:3:2:W032
......@@ -7,4 +7,4 @@
>>>>>>> branch2
}
~~~~~~~~~~
error:5:1
error:5:1:MERGECONFLICT1:Unresolved merge conflict
import os, sys
~~~~~~~~~~
error:1:10
error:1:10:E401
......@@ -4,4 +4,4 @@ function f() {
$this = "cannot be re-assigned";
}
~~~~~~~~~
error:4:
error:4:0:PHP2:Fatal Error
......@@ -4,4 +4,4 @@ function f() {
this is bad syntax;
}
~~~~~~~~~
error:4:
error:4:0:PHP1:Parse Error
......@@ -2,6 +2,6 @@ import sys, os
x += 1
~~~~~~~~~~
warning:1:
warning:1:
error:3:
warning:1:0
warning:1:0
error:3:0
......@@ -3,4 +3,4 @@
"""
Useless string """
~~~~~~~~~~
warning:4:0 See T9257.
warning:4:0:W0105:Pointless String Statement
......@@ -2,6 +2,8 @@ import sys, os
x += 1
~~~~~~~~~~
warning:1:0
advice:1:0
error:3:0
advice:1:0:C0111:Missing Docstring
advice:1:0:C0410:Multiple Imports
warning:1:0:W0611:Unused Import
warning:1:0:W0611:Unused Import
error:3:0:E0602:Undefined Variable
def hello()
end
~~~~~~~~~~
warning:1:10
warning:1:10:-
def hello()
puts "hello world"
~~~~~~~~~~
error:2:
error:2:0:RUBY:Syntax Error
......@@ -10,11 +10,11 @@ didn't remove acording
Added ZZZZsupermnZZZZ
Added full batmn batmnZZZZ
~~~~~~~~~~
warning:2:1
warning:4:10
warning:5:15
warning:7:7
warning:7:12
warning:9:15
warning:10:11
warning:11:12
warning:2:1:SPELL1:Possible Spelling Mistake
warning:4:10:SPELL2:Possible Spelling Mistake
warning:5:15:SPELL2:Possible Spelling Mistake
warning:7:7:SPELL2:Possible Spelling Mistake
warning:7:12:SPELL2:Possible Spelling Mistake
warning:9:15:SPELL1:Possible Spelling Mistake
warning:10:11:SPELL2:Possible Spelling Mistake
warning:11:12:SPELL1:Possible Spelling Mistake
❤♎☀★☂♞
~~~~~~~~~~
error:1:1
error:1:1:TXT5:Bad Charset
......@@ -4,6 +4,6 @@
The quick brown fox jumps over the lazy dog.
~~~~~~~~~~
autofix:1:1
autofix:1:1:TXT8:Leading Whitespace at BOF
~~~~~~~~~~
The quick brown fox jumps over the lazy dog.
The quick brown fox
jumps over the lazy dog.
~~~~~~~~~~
error:1:1
error:1:1:TXT1:DOS Newlines
~~~~~~~~~~
The quick brown fox
jumps over the lazy dog.
~~~~~~~~~~
error::
error:0:0:TXT10:Empty File
......@@ -4,6 +4,6 @@ The quick brown fox jumps over the lazy dog.
~~~~~~~~~~
autofix:2:1
autofix:2:1:TXT9:Trailing Whitespace at EOF
~~~~~~~~~~
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
~~~~~~~~~~
warning:1:1
warning:1:1:TXT3:Line Too Long
~~~~~~~~~~
~~~~~~~~~~
{"config": {"text.max-line-length": 40}}
The quick brown fox
jumps over the lazy dog.
~~~~~~~~~~
autofix:1:20
autofix:2:25
autofix:1:20:TXT6:Trailing Whitespace
autofix:2:25:TXT6:Trailing Whitespace
~~~~~~~~~~
The quick brown fox
jumps over the lazy dog.
......@@ -3,11 +3,11 @@ consectetur adipiscing elit.
Phasellus sodales nibh erat,
in hendrerit nulla dictum interdum.
~~~~~~~~~~
error:1:28
autofix:1:28
autofix:2:29
autofix:3:29
autofix:4:36
error:1:28:TXT2:Tab Literal
autofix:1:28:TXT6:Trailing Whitespace
autofix:2:29:TXT6:Trailing Whitespace
autofix:3:29:TXT6:Trailing Whitespace
autofix:4:36:TXT6:Trailing Whitespace
~~~~~~~~~~
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
......
......@@ -3,11 +3,11 @@ consectetur adipiscing elit.
Phasellus sodales nibh erat,
in hendrerit nulla dictum interdum.
~~~~~~~~~~
error:1:28
autofix:1:28
autofix:2:29
autofix:3:29
autofix:4:36
error:1:28:TXT2:Tab Literal
autofix:1:28:TXT6:Trailing Whitespace
autofix:2:29:TXT6:Trailing Whitespace
autofix:3:29:TXT6:Trailing Whitespace
autofix:4:36:TXT6:Trailing Whitespace
~~~~~~~~~~
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
......
......@@ -2,4 +2,4 @@
This shouldn't fatal the parser.
~~~~~~~~~~
disabled:2:1
disabled:2:1:XHP78:Inline HTML
<?php
~~~~~~~~~~
warning::
warning:0:0:XHP82:Empty File
......@@ -3,5 +3,5 @@
abstract class A {}
final class F {}
~~~~~~~~~~
disabled:3:1
disabled:4:1
disabled:3:1:XHP88:Class Not Extending `Phobject`
disabled:4:1:XHP88:Class Not Extending `Phobject`
......@@ -6,8 +6,12 @@ function f( ) {
g( );
}
~~~~~~~~~~
warning:5:12
warning:6:5
warning:5:12:XHP38:Declaration Formatting
warning:5:12:XHP25:Spaces Inside Parentheses
warning:5:12:XHP25:Spaces Inside Parentheses
warning:6:5:XHP37:Call Formatting
warning:6:5:XHP25:Spaces Inside Parentheses
warning:6:5:XHP25:Spaces Inside Parentheses
~~~~~~~~~~
<?php
......
<?php
char *buf = null;
~~~~~~~~~~
error:2:1
error:2:1:XHP1:PHP Syntax Error!
<?xml version="1.0" encoding="utf-8"?>
~~~~~~~~~~
error:2:1
error:2:1:XML4:LibXML Error
<bla>&#010100000000000000000000000000000000000000000000000060;</bla>
~~~~~~~~~~
error:1:63
error:1:63:XML9:LibXML Error
......@@ -3,4 +3,4 @@
<>
</languages>
~~~~~~~~~~
error:3:6
error:3:6:XML68:LibXML Error
......@@ -3,5 +3,5 @@
</lang>
</languages>
~~~~~~~~~~
error:3:16
error:4:1
error:3:16:XML76:LibXML Error
error:4:1:XML5:LibXML Error
......@@ -2,4 +2,4 @@
function __lambda_func() {}
~~~~~~~~~~
error:3:1
error:3:1:XHP68:`__lambda_func` Function
......@@ -24,4 +24,4 @@ abstract class SomeAbstractClass {
abstract public function __toString();
}
~~~~~~~~~~
error:6:7
error:6:7:XHP67:Throwing Exception in `__toString` Method
......@@ -3,4 +3,4 @@ abstract class SomeClass {
abstract public function someMethod() {}
}
~~~~~~~~~~
error:3:41
error:3:41:XHP108:`abstract` Method Cannot Contain Body
......@@ -3,4 +3,4 @@ abstract class SomeClass {
private abstract function someMethod();
}
~~~~~~~~~~
error:3:3
error:3:3:XHP107:`abstract` Method Cannot Be Declared `private`
......@@ -5,9 +5,9 @@ sizeof($x);
die();
sizeOf($x);
~~~~~~~~~~
advice:4:1
advice:5:1
advice:6:1
advice:4:1:XHP65:Alias Functions
advice:5:1:XHP65:Alias Functions
advice:6:1:XHP65:Alias Functions
~~~~~~~~~~
<?php
......
......@@ -3,4 +3,4 @@
array_combine($x, $x);
array_combine($x, $y);
~~~~~~~~~~
disabled:3:1
disabled:3:1:XHP84:`array_combine()` Unreliable