Skip to content

Commit

Permalink
Fix windows tests (#4040)
Browse files Browse the repository at this point in the history
* Fix windows tests by not mangling the expectations

* Use platform-dependent directory separator in expected messages

* fix CS
  • Loading branch information
weirdan committed Aug 22, 2020
1 parent 5bf7cc6 commit 4dcb718
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/ArrayFunctionCallTest.php
Expand Up @@ -1873,7 +1873,7 @@ function foo($data): void {
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
Expand Down
4 changes: 3 additions & 1 deletion tests/AssertAnnotationTest.php
@@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;

use const DIRECTORY_SEPARATOR;

class AssertAnnotationTest extends TestCase
{
use Traits\ValidCodeAnalysisTestTrait;
Expand Down Expand Up @@ -1455,7 +1457,7 @@ function foo($bar) : void {
if ($bar) {}
}',
'error_message' => 'RedundantCondition - src/somefile.php:19:29',
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:19:29',
],
'assertOneOfStrings' => [
'<?php
Expand Down
4 changes: 3 additions & 1 deletion tests/ClosureTest.php
@@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;

use const DIRECTORY_SEPARATOR;

class ClosureTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
Expand Down Expand Up @@ -794,7 +796,7 @@ function takesB(B $_b) : void {}
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
Expand Down
4 changes: 2 additions & 2 deletions tests/MagicMethodAnnotationTest.php
Expand Up @@ -804,7 +804,7 @@ public function foo(string $s) : C {
/** @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
Expand All @@ -819,7 +819,7 @@ public function foo(string $s) : C {
/** @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
Expand Down
4 changes: 2 additions & 2 deletions tests/PropertyTypeTest.php
Expand Up @@ -3079,7 +3079,7 @@ public function setAgain() : void {
$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
Expand All @@ -3100,7 +3100,7 @@ public function setAgain() : void {
$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
Expand Down
12 changes: 7 additions & 5 deletions tests/ReturnTypeTest.php
@@ -1,6 +1,8 @@
<?php
namespace Psalm\Tests;

use const DIRECTORY_SEPARATOR;

class ReturnTypeTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
Expand Down Expand Up @@ -1180,7 +1182,7 @@ function foo() : void {
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
Expand All @@ -1201,7 +1203,7 @@ function map(callable $predicate): callable {
$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
Expand All @@ -1223,7 +1225,7 @@ function($iter) use ($predicate) {
$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
Expand All @@ -1241,7 +1243,7 @@ function map(callable $predicate): callable {
$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
Expand All @@ -1256,7 +1258,7 @@ function map(): callable {
$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
Expand Down
2 changes: 1 addition & 1 deletion tests/SwitchTypeTest.php
Expand Up @@ -1162,7 +1162,7 @@ function foo(A $a) : void {
echo "goodbye";
}
}',
'error_message' => 'RedundantCondition - src/somefile.php:10',
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:10',
'error_levels' => ['ParadoxicalCondition'],
],
'repeatedCaseValue' => [
Expand Down
11 changes: 6 additions & 5 deletions tests/TaintTest.php
Expand Up @@ -3,6 +3,7 @@

use Psalm\Config;
use Psalm\Context;
use const DIRECTORY_SEPARATOR;

class TaintTest extends TestCase
{
Expand Down Expand Up @@ -520,7 +521,7 @@ function getName() : string {
}
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
Expand Down Expand Up @@ -691,7 +692,7 @@ public function deleteUser(PDO $pdo, string $userId) : void {
$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
Expand Down Expand Up @@ -761,7 +762,7 @@ public function deleteUser(PDO $pdo, string $userId, string $userId2) : void {
}
}
}',
'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
Expand Down Expand Up @@ -792,7 +793,7 @@ public function foo(string $user_id) : void {
}
(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
Expand Down Expand Up @@ -1370,7 +1371,7 @@ function identity(string $s) : string {
'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
Expand Down
2 changes: 1 addition & 1 deletion tests/Template/ClassTemplateExtendsTest.php
Expand Up @@ -5147,7 +5147,7 @@ function example($x) {
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
Expand Down
2 changes: 1 addition & 1 deletion tests/Traits/InvalidCodeAnalysisTestTrait.php
Expand Up @@ -69,7 +69,7 @@ public function testInvalidCode(

$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);

Expand Down

0 comments on commit 4dcb718

Please sign in to comment.