1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix windows tests (#4040)

* Fix windows tests by not mangling the expectations

* Use platform-dependent directory separator in expected messages

* fix CS
This commit is contained in:
Bruce Weirdan 2020-08-22 17:00:36 +03:00 committed by GitHub
parent 5bf7cc6434
commit 4dcb7183f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 20 deletions

View File

@ -1873,7 +1873,7 @@ class ArrayFunctionCallTest extends TestCase
function ints(array $ints) : void {}
$brr = array_filter([2,3,0,4,5]);
ints($brr);',
'error_message' => 'ArgumentTypeCoercion - src/somefile.php:5:26 - Argument 1 of ints expects list<int>, parent type array<int, int(2)|int(3)|int(4)|int(5)> provided',
'error_message' => 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:5:26 - Argument 1 of ints expects list<int>, parent type array<int, int(2)|int(3)|int(4)|int(5)> provided',
],
'usortOneParamInvalid' => [
'<?php

View File

@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;
use const DIRECTORY_SEPARATOR;
class AssertAnnotationTest extends TestCase
{
use Traits\ValidCodeAnalysisTestTrait;
@ -1455,7 +1457,7 @@ class AssertAnnotationTest extends TestCase
if ($bar) {}
}',
'error_message' => 'RedundantCondition - src/somefile.php:19:29',
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:19:29',
],
'assertOneOfStrings' => [
'<?php

View File

@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;
use const DIRECTORY_SEPARATOR;
class ClosureTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
@ -794,7 +796,7 @@ class ClosureTest extends TestCase
takesA($getAButReallyB());
takesB($getAButReallyB());',
'error_message' => 'ArgumentTypeCoercion - src/somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided',
'error_message' => 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided',
],
'closureByRefUseToMixed' => [
'<?php

View File

@ -804,7 +804,7 @@ class MagicMethodAnnotationTest extends TestCase
/** @method D foo(string $s) */
class B extends A {}',
'error_message' => 'ImplementedReturnTypeMismatch - src/somefile.php:11:33',
'error_message' => 'ImplementedReturnTypeMismatch - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:33',
],
'magicMethodOverridesParentWithDifferentParamType' => [
'<?php
@ -819,7 +819,7 @@ class MagicMethodAnnotationTest extends TestCase
/** @method D foo(int $s) */
class B extends A {}',
'error_message' => 'ImplementedParamTypeMismatch - src/somefile.php:11:21',
'error_message' => 'ImplementedParamTypeMismatch - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:21',
],
'parseBadMethodAnnotation' => [
'<?php

View File

@ -3079,7 +3079,7 @@ class PropertyTypeTest extends TestCase
$a = new A();
$a->bar = "goodbye";',
'error_message' => 'InaccessibleProperty - src/somefile.php:19:21',
'error_message' => 'InaccessibleProperty - src' . DIRECTORY_SEPARATOR . 'somefile.php:19:21',
],
'readonlyPublicPropertySetInConstructorAndAlsoOutsideClass' => [
'<?php
@ -3100,7 +3100,7 @@ class PropertyTypeTest extends TestCase
$a = new A();
$a->bar = "goodbye";',
'error_message' => 'InaccessibleProperty - src/somefile.php:18:21',
'error_message' => 'InaccessibleProperty - src' . DIRECTORY_SEPARATOR . 'somefile.php:18:21',
],
'addNullToMixedAfterNullablePropertyFetch' => [
'<?php

View File

@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;
use const DIRECTORY_SEPARATOR;
class ReturnTypeTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
@ -1180,7 +1182,7 @@ class ReturnTypeTest extends TestCase
function f1(
int $a
): string {}',
'error_message' => 'InvalidReturnType - src/somefile.php:4:24',
'error_message' => 'InvalidReturnType - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:24',
],
'cannotInferReturnClosureWithoutReturn' => [
'<?php
@ -1201,7 +1203,7 @@ class ReturnTypeTest extends TestCase
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'MixedAssignment - src/somefile.php:10:51 - Unable to determine the type that $value is being assigned to',
'error_message' => 'MixedAssignment - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:51 - Unable to determine the type that $value is being assigned to',
],
'cannotInferReturnClosureWithMoreSpecificTypes' => [
'<?php
@ -1223,7 +1225,7 @@ class ReturnTypeTest extends TestCase
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'InvalidArgument - src/somefile.php:13:54 - Argument 1 expects T:fn-map as mixed, int provided',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:54 - Argument 1 expects T:fn-map as mixed, int provided',
],
'cannotInferReturnClosureWithDifferentReturnTypes' => [
'<?php
@ -1241,7 +1243,7 @@ class ReturnTypeTest extends TestCase
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'InvalidReturnStatement - src/somefile.php:9:28 - The inferred type \'Closure(iterable<mixed, T:fn-map as mixed>):int(1)\' does not match the declared return type \'callable(iterable<mixed, T:fn-map as mixed>):iterable<mixed, U:fn-map as mixed>\' for map',
'error_message' => 'InvalidReturnStatement - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:28 - The inferred type \'Closure(iterable<mixed, T:fn-map as mixed>):int(1)\' does not match the declared return type \'callable(iterable<mixed, T:fn-map as mixed>):iterable<mixed, U:fn-map as mixed>\' for map',
],
'cannotInferReturnClosureWithDifferentTypes' => [
'<?php
@ -1256,7 +1258,7 @@ class ReturnTypeTest extends TestCase
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'InvalidReturnStatement - src/somefile.php:8:28 - The inferred type \'Closure(B):void\' does not match the declared return type \'callable(A):void\' for map',
'error_message' => 'InvalidReturnStatement - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:28 - The inferred type \'Closure(B):void\' does not match the declared return type \'callable(A):void\' for map',
],
'compareObjectLikeToAlwaysFilledArray' => [
'<?php

View File

@ -1162,7 +1162,7 @@ class SwitchTypeTest extends TestCase
echo "goodbye";
}
}',
'error_message' => 'RedundantCondition - src/somefile.php:10',
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:10',
'error_levels' => ['ParadoxicalCondition'],
],
'repeatedCaseValue' => [

View File

@ -3,6 +3,7 @@ namespace Psalm\Tests;
use Psalm\Config;
use Psalm\Context;
use const DIRECTORY_SEPARATOR;
class TaintTest extends TestCase
{
@ -520,7 +521,7 @@ class TaintTest extends TestCase
}
echo getName();',
'error_message' => 'TaintedInput - src/somefile.php:6:26 - Detected tainted html in path: $_GET -> $_GET[\'name\'] (src/somefile.php:3:32) -> getname (src/somefile.php:6:26) -> call to echo (src/somefile.php:6:26) -> echo#1',
'error_message' => 'TaintedInput - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:26 - Detected tainted html in path: $_GET -> $_GET[\'name\'] (src/somefile.php:3:32) -> getname (src/somefile.php:6:26) -> call to echo (src/somefile.php:6:26) -> echo#1',
],
'taintedInputFromExplicitTaintSource' => [
'<?php
@ -691,7 +692,7 @@ class TaintTest extends TestCase
$pdo->exec("delete from users where user_id = " . $userId);
}
}',
'error_message' => 'TaintedInput - src/somefile.php:17:40 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:4:45) -> A::getUserId (src/somefile.php:3:55) -> concat (src/somefile.php:8:36) -> A::getAppendedUserId (src/somefile.php:7:63) -> $userId (src/somefile.php:12:29) -> call to A::deleteUser (src/somefile.php:13:53) -> A::deleteUser#2 (src/somefile.php:16:69) -> concat (src/somefile.php:17:40) -> call to PDO::exec (src/somefile.php:17:40) -> PDO::exec#1',
'error_message' => 'TaintedInput - src' . DIRECTORY_SEPARATOR . 'somefile.php:17:40 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:4:45) -> A::getUserId (src/somefile.php:3:55) -> concat (src/somefile.php:8:36) -> A::getAppendedUserId (src/somefile.php:7:63) -> $userId (src/somefile.php:12:29) -> call to A::deleteUser (src/somefile.php:13:53) -> A::deleteUser#2 (src/somefile.php:16:69) -> concat (src/somefile.php:17:40) -> call to PDO::exec (src/somefile.php:17:40) -> PDO::exec#1',
],
'taintedInputToParam' => [
'<?php
@ -761,7 +762,7 @@ class TaintTest extends TestCase
}
}
}',
'error_message' => 'TaintedInput - src/somefile.php:23:44 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:7:67) -> call to A::getAppendedUserId (src/somefile.php:7:58) -> A::getAppendedUserId#1 (src/somefile.php:11:66) -> concat (src/somefile.php:12:36) -> A::getAppendedUserId (src/somefile.php:11:41) -> call to A::deleteUser (src/somefile.php:7:33) -> A::deleteUser#3 (src/somefile.php:19:85) -> concat (src/somefile.php:23:44) -> call to PDO::exec (src/somefile.php:23:44) -> PDO::exec#1',
'error_message' => 'TaintedInput - src' . DIRECTORY_SEPARATOR . 'somefile.php:23:44 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:7:67) -> call to A::getAppendedUserId (src/somefile.php:7:58) -> A::getAppendedUserId#1 (src/somefile.php:11:66) -> concat (src/somefile.php:12:36) -> A::getAppendedUserId (src/somefile.php:11:41) -> call to A::deleteUser (src/somefile.php:7:33) -> A::deleteUser#3 (src/somefile.php:19:85) -> concat (src/somefile.php:23:44) -> call to PDO::exec (src/somefile.php:23:44) -> PDO::exec#1',
],
'taintedInParentLoader' => [
'<?php
@ -792,7 +793,7 @@ class TaintTest extends TestCase
}
(new C)->foo((string) $_GET["user_id"]);',
'error_message' => 'TaintedInput - src/somefile.php:16:44 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:28:43) -> call to C::foo (src/somefile.php:28:34) -> C::foo#1 (src/somefile.php:23:52) -> call to AGrandChild::loadFull (src/somefile.php:24:51) -> AGrandChild::loadFull#1 (src/somefile.php:5:64) -> A::loadFull#1 (src/somefile.php:24:51) -> call to A::loadPartial (src/somefile.php:6:49) -> A::loadPartial#1 (src/somefile.php:3:76) -> AChild::loadPartial#1 (src/somefile.php:6:49) -> concat (src/somefile.php:16:44) -> call to PDO::exec (src/somefile.php:16:44) -> PDO::exec#1',
'error_message' => 'TaintedInput - src' . DIRECTORY_SEPARATOR . 'somefile.php:16:44 - Detected tainted sql in path: $_GET -> $_GET[\'user_id\'] (src/somefile.php:28:43) -> call to C::foo (src/somefile.php:28:34) -> C::foo#1 (src/somefile.php:23:52) -> call to AGrandChild::loadFull (src/somefile.php:24:51) -> AGrandChild::loadFull#1 (src/somefile.php:5:64) -> A::loadFull#1 (src/somefile.php:24:51) -> call to A::loadPartial (src/somefile.php:6:49) -> A::loadPartial#1 (src/somefile.php:3:76) -> AChild::loadPartial#1 (src/somefile.php:6:49) -> concat (src/somefile.php:16:44) -> call to PDO::exec (src/somefile.php:16:44) -> PDO::exec#1',
],
'taintedInputFromProperty' => [
'<?php
@ -1370,7 +1371,7 @@ class TaintTest extends TestCase
'print' => [
'<?php
print($_GET["name"]);',
'error_message' => 'TaintedInput - src/somefile.php:2:27 - Detected tainted html in path: $_GET -> $_GET[\'name\'] (src/somefile.php:2:27) -> call to print (src/somefile.php:2:27) -> print#1',
'error_message' => 'TaintedInput - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:27 - Detected tainted html in path: $_GET -> $_GET[\'name\'] (src/somefile.php:2:27) -> call to print (src/somefile.php:2:27) -> print#1',
],
'unpackArgs' => [
'<?php

View File

@ -5147,7 +5147,7 @@ class ClassTemplateExtendsTest extends TestCase
function bar(Child $c) : void {
ord($c->example("boris"));
}',
'error_message' => 'MixedArgument - src/somefile.php:31:29 - Argument 1 of ord cannot be mixed, expecting string',
'error_message' => 'MixedArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:31:29 - Argument 1 of ord cannot be mixed, expecting string',
],
'preventWiderParentType' => [
'<?php

View File

@ -69,7 +69,7 @@ trait InvalidCodeAnalysisTestTrait
$file_path = self::$src_dir_path . 'somefile.php';
$error_message = preg_replace('/ src[\/\\\\]somefile\.php/', ' src/somefile.php', $error_message);
// $error_message = preg_replace('/ src[\/\\\\]somefile\.php/', ' src/somefile.php', $error_message);
$this->expectException(\Psalm\Exception\CodeException::class);