-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indicate file on TypeInferenceTestCase validation errors #3166
Conversation
This pull request has been marked as ready for review. |
I will finalize this PR when back at my windows laptop next week |
This pull request has been marked as ready for review. |
$functionName, | ||
$pathHelper->getRelativePath(strtr($file, '\\', '/')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to change the backslashes here I think. And if you wanted to, we have FileHelper::normalizePath()
for that. You can run this function on both sides here (implementation & tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the currentWorkingDirectory in
if ($this->currentWorkingDirectory !== '' && str_starts_with($filename, $this->currentWorkingDirectory)) { |
when not doing strtr($file, '\\', '/')
we pass on windows a path with backslashes and this makes the path not getting returned relative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just tried FileHelper::normalize
instead of strtr($file, '\\', '/')
: it will not turn the slashes in the correct form to make $pathHelper->getRelativePath
return a proper relative path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't it? It works everywhere else in PHPStan's codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
in other places we also do the \\ -> /
dance to make it work:
phpstan-src/tests/e2e/ResultCacheEndToEndTest.php
Lines 194 to 199 in 494b7b0
private function relativizePath(string $path): string | |
{ | |
$path = str_replace('\\', '/', $path); | |
$helper = new SimpleRelativePathHelper(str_replace('\\', '/', __DIR__ . '/PHP-Parser')); | |
return $helper->getRelativePath($path); | |
} |
but I found a way to make it work.
45b7661
to
afa4cb9
Compare
@@ -143,8 +145,10 @@ public function assertFileAsserts( | |||
*/ | |||
public static function gatherAssertTypes(string $file): array | |||
{ | |||
$pathHelper = new SimpleRelativePathHelper(dirname(__DIR__, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense as it will be somewhere deep in the PHAR, for users that use TypeInferenceTestCase outside of phpstan-src.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last try in the latest git push. if this doesn't work for you I will close this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I committed my vision how it should have been done: 0e53118
Thank you. As a next step we could stop using SimpleRelativePathHelper in more places in tests and start using SystemAgnosticSimpleRelativePathHelper instead. It could find more issues like it did here in PathConstantsTest. |
was just hunting down a bug in one of my PRs, but wasn't able to find the offending file, because the error message did not indicate which file the error related to
before this PR:
after this PR:
note the added filename in the error message