Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/__tests__/ArcanistLinterTestCase.php
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | private function lintFile($file, ArcanistLinter $linter) { | ||||
$contents = preg_split('/^~{4,}\n/m', $contents); | $contents = preg_split('/^~{4,}\n/m', $contents); | ||||
if (count($contents) < 2) { | if (count($contents) < 2) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
"Expected '%s' separating test case and results.", | "Expected '%s' separating test case and results.", | ||||
'~~~~~~~~~~')); | '~~~~~~~~~~')); | ||||
} | } | ||||
list($data, $expect, $xform, $config) = array_merge( | list($data, $expect, $xform, $config, $tmp_filename) = array_merge( | ||||
cspeckmim: Unfortunately both `checkstyle` and `pmd`/`cpd` do absolutely nothing if the file extensions… | |||||
$contents, | $contents, | ||||
array(null, null)); | array(null, null, null)); | ||||
$basename = basename($file); | $basename = basename($file); | ||||
if ($config) { | if ($config) { | ||||
$config = phutil_json_decode($config); | $config = phutil_json_decode($config); | ||||
} else { | } else { | ||||
$config = array(); | $config = array(); | ||||
} | } | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$config, | $config, | ||||
array( | array( | ||||
'config' => 'optional map<string, wild>', | 'config' => 'optional map<string, wild>', | ||||
'path' => 'optional string', | 'path' => 'optional string', | ||||
'mode' => 'optional string', | 'mode' => 'optional string', | ||||
'stopped' => 'optional bool', | 'stopped' => 'optional bool', | ||||
)); | )); | ||||
$exception = null; | $exception = null; | ||||
$after_lint = null; | $after_lint = null; | ||||
$messages = null; | $messages = null; | ||||
$exception_message = false; | $exception_message = false; | ||||
$caught_exception = false; | $caught_exception = false; | ||||
try { | try { | ||||
$tmp = new TempFile($basename); | if (!$tmp_filename) { | ||||
$tmp_filename = $basename; | |||||
} | |||||
$tmp = new TempFile($tmp_filename); | |||||
Filesystem::writeFile($tmp, $data); | Filesystem::writeFile($tmp, $data); | ||||
$full_path = (string)$tmp; | $full_path = (string)$tmp; | ||||
$mode = idx($config, 'mode'); | $mode = idx($config, 'mode'); | ||||
if ($mode) { | if ($mode) { | ||||
Filesystem::changePermissions($tmp, octdec($mode)); | Filesystem::changePermissions($tmp, octdec($mode)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |
Unfortunately both checkstyle and pmd/cpd do absolutely nothing if the file extensions don't match as expected (or it might be just that way for java files). This allows for the UT lint-test file to specify what filename should be used when writing out the code, to be passed to the linter.