Skip to content

2>&1 expression leads to all Psalm unrelated STDERR breaking report parsing #54

@Ocramius

Description

@Ocramius

I'm currently working on psalm/psalm-plugin-phpunit#149

The tests there fail like this:

47) TestCase: Providers returning null are flagged
 Test  tests/acceptance/TestCase.feature:Providers returning null are flagged
Failed to parse output: 
JIT acceleration: ON

Target PHP version: 8.3 (inferred from current PHP version).

Scanning files...

579 / 579...

Analyzing files...

E
[{"link":"https:\/\/psalm.dev\/011","severity":"error","line_from":5,"line_to":5,"type":"InvalidReturnType","message":"Providers must return iterable<array-key, array<array-key, mixed>>, null provided","file_name":"509d09d0079a705e876f5aa25f1c1b063e65cf9a.php","file_path":"\/home\/ocramius\/Documents\/psalm\/phpunit-psalm-plugin\/tests\/_run\/509d09d0079a705e876f5aa25f1c1b063e65cf9a.php","snippet":"  \/** @return null *\/","selected_text":"null","from":102,"to":106,"snippet_from":88,"snippet_to":109,"column_from":15,"column_to":19,"shortcode":11,"error_level":6,"taint_trace":null,"other_references":null}]
Error:Syntax error

Scenario Steps:

 15. $I->canSeeNoErrors()
 14. $I->canSeeTheseErrors("| Type              | Message                                                                           |\n| InvalidReturnType | Providers must return iterable<array-key, array<array-key, mixed>>, null provided |")
 13. $I->runPsalm()
 12. $I->haveTheFollowingCode("class MyTestCase extends TestCase {\n  /** @return null */\n  public function provide() {\n    return null;\n  }\n  /** @dataProvider provide */\n  public function testSomething(): void {}\n}")
 11. $I->haveTheFollowingCodePreamble("<?php\nnamespace NS;\nuse PHPUnit\\Framework\\TestCase;\n")
 10. $I->haveTheFollowingConfig("<?xml version="1.0"?>\n<psalm errorLevel="1" findUnusedCode="false" %s>\n  <projectFiles>\n    <directory name="."/>\n    <ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>\n  </projectFiles>\n  <plugins>\n    <pluginClass clas...")

From what I can see, the tool attempts to parse this prefix section (STDERR):

JIT acceleration: ON

Target PHP version: 8.3 (inferred from current PHP version).

Scanning files...

579 / 579...

Analyzing files...

E

I'm suggesting here that we drop the STDERR redirection in this location:

$cmd = $this->getPsalmPath()
. ' --output-format=json '
. ($suppressProgress ? ' --no-progress ' : ' ')
. join(' ', $options) . ' '
. ($filename ? escapeshellarg($filename) : '')
. ' 2>&1';
$this->debug('Running: ' . $cmd);
$this->cli()->runShellCommand($cmd, false);

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions