From 29921155345be033f2aaa0c8d87a349cfd30851d Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Fri, 3 Feb 2023 22:20:06 +0100 Subject: [PATCH 1/5] Migrate to new testing library --- .github/workflows/ci.yml | 6 +++--- composer.json | 2 +- .../lang/ast/unittest/EmitterTest.class.php | 8 ++++---- .../lang/ast/unittest/ResultTest.class.php | 6 +++--- .../ast/unittest/TypeLiteralsTest.class.php | 18 ++++++++--------- .../unittest/cli/CompileOnlyTest.class.php | 2 +- .../ast/unittest/cli/FromFileTest.class.php | 2 +- .../unittest/cli/FromFilesInTest.class.php | 4 ++-- .../ast/unittest/cli/FromInputsTest.class.php | 6 +++--- .../lang/ast/unittest/cli/InputTest.class.php | 4 ++-- .../ast/unittest/cli/OutputTest.class.php | 4 ++-- .../ast/unittest/cli/ToArchiveTest.class.php | 2 +- .../ast/unittest/cli/ToFileTest.class.php | 2 +- .../ast/unittest/cli/ToFolderTest.class.php | 4 ++-- .../ast/unittest/cli/ToStreamTest.class.php | 2 +- .../unittest/emit/AnnotationSupport.class.php | 2 +- .../emit/AnonymousClassTest.class.php | 2 +- .../emit/ArgumentPromotionTest.class.php | 4 ++-- .../emit/ArgumentUnpackingTest.class.php | 2 +- .../unittest/emit/ArrayTypesTest.class.php | 2 +- .../ast/unittest/emit/ArraysTest.class.php | 4 ++-- .../ast/unittest/emit/BlockTest.class.php | 2 +- .../ast/unittest/emit/BracesTest.class.php | 2 +- .../emit/CallableSyntaxTest.class.php | 2 +- .../ast/unittest/emit/CastingTest.class.php | 2 +- .../unittest/emit/ClassLiteralTest.class.php | 2 +- .../ast/unittest/emit/CommentsTest.class.php | 2 +- .../emit/ControlStructuresTest.class.php | 6 +++--- .../unittest/emit/DeclarationTest.class.php | 2 +- .../ast/unittest/emit/DeclareTest.class.php | 6 +++--- .../lang/ast/unittest/emit/EchoTest.class.php | 2 +- .../unittest/emit/EmitterTraitTest.class.php | 4 ++-- .../ast/unittest/emit/EmittingTest.class.php | 2 +- .../lang/ast/unittest/emit/EnumTest.class.php | 8 ++++---- .../ast/unittest/emit/EscapingTest.class.php | 2 +- .../unittest/emit/ExceptionsTest.class.php | 2 +- .../unittest/emit/FunctionTypesTest.class.php | 2 +- .../unittest/emit/GeneratedCodeTest.class.php | 6 +++--- .../lang/ast/unittest/emit/GotoTest.class.php | 2 +- .../ast/unittest/emit/ImportTest.class.php | 2 +- .../InitializeWithExpressionsTest.class.php | 6 +++--- .../unittest/emit/InstanceOfTest.class.php | 2 +- .../unittest/emit/InstantiationTest.class.php | 2 +- .../emit/IntersectionTypesTest.class.php | 12 +++++------ .../unittest/emit/InvocationTest.class.php | 8 ++++---- .../ast/unittest/emit/LambdasTest.class.php | 8 ++++---- .../ast/unittest/emit/LoopsTest.class.php | 2 +- .../ast/unittest/emit/MembersTest.class.php | 2 +- .../unittest/emit/MultipleCatchTest.class.php | 2 +- .../unittest/emit/NamespacesTest.class.php | 2 +- .../emit/NullCoalesceAssignmentTest.class.php | 2 +- .../unittest/emit/NullCoalesceTest.class.php | 2 +- .../ast/unittest/emit/NullSafeTest.class.php | 2 +- .../emit/OmitConstModifiersTest.class.php | 4 ++-- .../ast/unittest/emit/OmitTypesTest.class.php | 2 +- .../ast/unittest/emit/PHP81Test.class.php | 2 +- .../ast/unittest/emit/PHP82Test.class.php | 2 +- .../ast/unittest/emit/ParameterTest.class.php | 8 ++++---- .../unittest/emit/PrecedenceTest.class.php | 2 +- .../unittest/emit/PropertyTypesTest.class.php | 2 +- .../ast/unittest/emit/ReadonlyTest.class.php | 20 +++++++++---------- .../unittest/emit/ReflectionTest.class.php | 10 +++++----- .../ast/unittest/emit/ReturnTest.class.php | 2 +- .../emit/RewriteClassOnObjectsTest.class.php | 4 ++-- .../RewriteLambdaExpressionsTest.class.php | 4 ++-- .../emit/RewriteMultiCatchTest.class.php | 4 ++-- .../ast/unittest/emit/ScalarsTest.class.php | 2 +- .../unittest/emit/SyntaxErrorsTest.class.php | 10 +++++----- .../ast/unittest/emit/TernaryTest.class.php | 2 +- .../emit/TrailingCommasTest.class.php | 2 +- .../ast/unittest/emit/TraitsTest.class.php | 6 +++--- .../emit/TransformationsTest.class.php | 2 +- .../emit/TypeDeclarationTest.class.php | 2 +- .../emit/UnicodeEscapesTest.class.php | 2 +- .../unittest/emit/UnionTypesTest.class.php | 14 ++++++------- .../ast/unittest/emit/UsingTest.class.php | 2 +- .../ast/unittest/emit/VarargsTest.class.php | 2 +- .../emit/VirtualPropertyTypesTest.class.php | 14 ++++++------- .../ast/unittest/emit/YieldTest.class.php | 2 +- .../loader/CompilingClassLoaderTest.class.php | 10 +++++----- 80 files changed, 168 insertions(+), 168 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ceca1e9d..645ef0ef 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: git config --system core.autocrlf false; git config --system core.eol lf - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up PHP ${{ matrix.php-versions }} uses: shivammathur/setup-php@v2 @@ -43,7 +43,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2.1.3 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} @@ -56,4 +56,4 @@ jobs: echo "vendor/autoload.php" > composer.pth - name: Run test suite - run: sh xp-run xp.unittest.TestRunner src/test/php + run: sh xp-run xp.test.Runner src/test/php diff --git a/composer.json b/composer.json index 5c312305..2be195bd 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "php" : ">=7.0.0" }, "require-dev" : { - "xp-framework/unittest": "^11.0 | ^10.0" + "xp-framework/test": "dev-main" }, "bin": ["bin/xp.xp-framework.compiler.compile", "bin/xp.xp-framework.compiler.ast"], "autoload" : { diff --git a/src/test/php/lang/ast/unittest/EmitterTest.class.php b/src/test/php/lang/ast/unittest/EmitterTest.class.php index 347ff56e..23050040 100755 --- a/src/test/php/lang/ast/unittest/EmitterTest.class.php +++ b/src/test/php/lang/ast/unittest/EmitterTest.class.php @@ -1,10 +1,10 @@ literal($type)); } - #[Test, Values('php71')] + #[Test, Values(from: 'php71')] public function php71_literals($type, $literal) { Assert::equals($literal, (new PHP71())->literal($type)); } - #[Test, Values('php72')] + #[Test, Values(from: 'php72')] public function php72_literals($type, $literal) { Assert::equals($literal, (new PHP72())->literal($type)); } - #[Test, Values('php74')] + #[Test, Values(from: 'php74')] public function php74_literals($type, $literal) { Assert::equals($literal, (new PHP74())->literal($type)); } - #[Test, Values('php80')] + #[Test, Values(from: 'php80')] public function php80_literals($type, $literal) { Assert::equals($literal, (new PHP80())->literal($type)); } - #[Test, Values('php81')] + #[Test, Values(from: 'php81')] public function php81_literals($type, $literal) { Assert::equals($literal, (new PHP81())->literal($type)); } - #[Test, Values('php82')] + #[Test, Values(from: 'php82')] public function php82_literals($type, $literal) { Assert::equals($literal, (new PHP82())->literal($type)); } diff --git a/src/test/php/lang/ast/unittest/cli/CompileOnlyTest.class.php b/src/test/php/lang/ast/unittest/cli/CompileOnlyTest.class.php index c62a8da3..f5590344 100755 --- a/src/test/php/lang/ast/unittest/cli/CompileOnlyTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/CompileOnlyTest.class.php @@ -1,6 +1,6 @@ folder->getURI()); } - #[Test, Values('files')] + #[Test, Values(from: 'files')] public function iteration($expected) { $results= []; foreach (new FromFilesIn($this->folder) as $path => $stream) { diff --git a/src/test/php/lang/ast/unittest/cli/FromInputsTest.class.php b/src/test/php/lang/ast/unittest/cli/FromInputsTest.class.php index 8c3e09c8..1832bbf0 100755 --- a/src/test/php/lang/ast/unittest/cli/FromInputsTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/FromInputsTest.class.php @@ -1,7 +1,7 @@ $stream) { diff --git a/src/test/php/lang/ast/unittest/cli/InputTest.class.php b/src/test/php/lang/ast/unittest/cli/InputTest.class.php index dc58270e..90d2b2c3 100755 --- a/src/test/php/lang/ast/unittest/cli/InputTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/InputTest.class.php @@ -2,9 +2,9 @@ use io\{File, Folder}; use lang\{Environment, IllegalArgumentException}; -use unittest\{Assert, After, Before, Expect, Test, Values}; +use test\{After, Assert, Before, Expect, Test, Values}; use util\cmd\Console; -use xp\compiler\{Input, FromStream, FromFile, FromFilesIn, FromInputs}; +use xp\compiler\{FromFile, FromFilesIn, FromInputs, FromStream, Input}; class InputTest { private $folder, $file; diff --git a/src/test/php/lang/ast/unittest/cli/OutputTest.class.php b/src/test/php/lang/ast/unittest/cli/OutputTest.class.php index 4821b25e..c4369971 100755 --- a/src/test/php/lang/ast/unittest/cli/OutputTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/OutputTest.class.php @@ -2,9 +2,9 @@ use io\{File, Folder}; use lang\Environment; -use unittest\{Assert, After, Before, Test, Values}; +use test\{After, Assert, Before, Test, Values}; use util\cmd\Console; -use xp\compiler\{Output, CompileOnly, ToStream, ToFile, ToArchive, ToFolder}; +use xp\compiler\{CompileOnly, Output, ToArchive, ToFile, ToFolder, ToStream}; class OutputTest { private $folder, $file, $archive; diff --git a/src/test/php/lang/ast/unittest/cli/ToArchiveTest.class.php b/src/test/php/lang/ast/unittest/cli/ToArchiveTest.class.php index 6b2067ef..53c19921 100755 --- a/src/test/php/lang/ast/unittest/cli/ToArchiveTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/ToArchiveTest.class.php @@ -3,7 +3,7 @@ use io\{File, Folder}; use lang\Environment; use lang\archive\ArchiveClassLoader; -use unittest\{After, Assert, Before, Test}; +use test\{After, Assert, Before, Test}; use xp\compiler\ToArchive; class ToArchiveTest { diff --git a/src/test/php/lang/ast/unittest/cli/ToFileTest.class.php b/src/test/php/lang/ast/unittest/cli/ToFileTest.class.php index 72be2ef4..43c2bef1 100755 --- a/src/test/php/lang/ast/unittest/cli/ToFileTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/ToFileTest.class.php @@ -3,7 +3,7 @@ use io\{File, Folder}; use lang\Environment; use lang\FileSystemClassLoader; -use unittest\{After, Assert, Before, Test}; +use test\{After, Assert, Before, Test}; use xp\compiler\ToFile; class ToFileTest { diff --git a/src/test/php/lang/ast/unittest/cli/ToFolderTest.class.php b/src/test/php/lang/ast/unittest/cli/ToFolderTest.class.php index 0c6d3c61..b3fe466c 100755 --- a/src/test/php/lang/ast/unittest/cli/ToFolderTest.class.php +++ b/src/test/php/lang/ast/unittest/cli/ToFolderTest.class.php @@ -1,9 +1,9 @@ type('class { public function __construct(private string... $in) { } diff --git a/src/test/php/lang/ast/unittest/emit/ArgumentUnpackingTest.class.php b/src/test/php/lang/ast/unittest/emit/ArgumentUnpackingTest.class.php index cbf78e8c..61dd3b98 100755 --- a/src/test/php/lang/ast/unittest/emit/ArgumentUnpackingTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/ArgumentUnpackingTest.class.php @@ -1,6 +1,6 @@ run('class { public function run() { diff --git a/src/test/php/lang/ast/unittest/emit/BlockTest.class.php b/src/test/php/lang/ast/unittest/emit/BlockTest.class.php index 37f58f37..d5eeee37 100755 --- a/src/test/php/lang/ast/unittest/emit/BlockTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/BlockTest.class.php @@ -1,6 +1,6 @@ run('class { public function run($arg) { @@ -167,7 +167,7 @@ public function run($arg) { }', SEEK_END); } - #[Test, Expect(class: Throwable::class, withMessage: '/Unknown seek mode .+/')] + #[Test, Expect(class: Throwable::class, message: '/Unknown seek mode .+/')] public function match_with_throw_expression() { $this->run('class { public function run($arg) { diff --git a/src/test/php/lang/ast/unittest/emit/DeclarationTest.class.php b/src/test/php/lang/ast/unittest/emit/DeclarationTest.class.php index 2c674f47..8cf02941 100755 --- a/src/test/php/lang/ast/unittest/emit/DeclarationTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/DeclarationTest.class.php @@ -3,7 +3,7 @@ use lang\ast\emit\Declaration; use lang\ast\nodes\{ClassDeclaration, Property}; use lang\ast\types\IsValue; -use unittest\{Assert, Before, Test, Expect}; +use test\{Assert, Before, Expect, Test}; class DeclarationTest { private $type; diff --git a/src/test/php/lang/ast/unittest/emit/DeclareTest.class.php b/src/test/php/lang/ast/unittest/emit/DeclareTest.class.php index 860ebd35..fd5623ed 100755 --- a/src/test/php/lang/ast/unittest/emit/DeclareTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/DeclareTest.class.php @@ -1,7 +1,7 @@ run('declare(strict_types = 1); class { public static function number(int $n) { return $n; } public function run() { return self::number("1"); } }'); } -} +} \ No newline at end of file diff --git a/src/test/php/lang/ast/unittest/emit/EchoTest.class.php b/src/test/php/lang/ast/unittest/emit/EchoTest.class.php index a6f1d87a..97b3215f 100755 --- a/src/test/php/lang/ast/unittest/emit/EchoTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/EchoTest.class.php @@ -1,6 +1,6 @@ function_exists("enum_exists"))')] +#[Condition(assert: 'fn() => function_exists("enum_exists")')] class EnumTest extends EmittingTest { #[Test] @@ -138,7 +138,7 @@ public function backed_enum_from_string($arg, $expected) { Assert::equals($expected, $t->getMethod('from')->invoke(null, [$arg])->name); } - #[Test, Expect(class: Error::class, withMessage: '/"illegal" is not a valid backing value for enum .+/')] + #[Test, Expect(class: Error::class, message: '/"illegal" is not a valid backing value for enum .+/')] public function backed_enum_from_nonexistant() { $t= $this->type('enum : string { case ASC = "asc"; diff --git a/src/test/php/lang/ast/unittest/emit/EscapingTest.class.php b/src/test/php/lang/ast/unittest/emit/EscapingTest.class.php index 9a9e8e31..946b025c 100755 --- a/src/test/php/lang/ast/unittest/emit/EscapingTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/EscapingTest.class.php @@ -2,7 +2,7 @@ use io\streams\MemoryOutputStream; use lang\ast\emit\Escaping; -use unittest\{Assert, Test}; +use test\{Assert, Test}; class EscapingTest { diff --git a/src/test/php/lang/ast/unittest/emit/ExceptionsTest.class.php b/src/test/php/lang/ast/unittest/emit/ExceptionsTest.class.php index f55c529d..77ca0181 100755 --- a/src/test/php/lang/ast/unittest/emit/ExceptionsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/ExceptionsTest.class.php @@ -1,7 +1,7 @@ run(sprintf('use lang\ast\unittest\emit\{FileInput, Handle}; class { const INITIAL= "initial"; @@ -39,7 +39,7 @@ public function run() { }', $declaration))); } - #[Test, Values('expressions')] + #[Test, Values(from: 'expressions')] public function reflective_access_to_property($declaration, $expected) { Assert::equals($expected, $this->run(sprintf('use lang\ast\unittest\emit\{FileInput, Handle}; class { const INITIAL= "initial"; diff --git a/src/test/php/lang/ast/unittest/emit/InstanceOfTest.class.php b/src/test/php/lang/ast/unittest/emit/InstanceOfTest.class.php index 0a62b39a..1659ceb3 100755 --- a/src/test/php/lang/ast/unittest/emit/InstanceOfTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/InstanceOfTest.class.php @@ -1,6 +1,6 @@ =8.1.0-dev")')] + #[Test, Runtime(php: '>=8.1.0-dev')] public function field_type_restriction_with_php81() { $t= $this->type('class { private Traversable&Countable $test; @@ -59,7 +59,7 @@ public function field_type_restriction_with_php81() { ); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.1.0-dev")')] + #[Test, Runtime(php: '>=8.1.0-dev')] public function parameter_type_restriction_with_php81() { $t= $this->type('class { public function test(Traversable&Countable $arg) { } @@ -71,7 +71,7 @@ public function test(Traversable&Countable $arg) { } ); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.1.0-dev")')] + #[Test, Runtime(php: '>=8.1.0-dev')] public function return_type_restriction_with_php81() { $t= $this->type('class { public function test(): Traversable&Countable { } diff --git a/src/test/php/lang/ast/unittest/emit/InvocationTest.class.php b/src/test/php/lang/ast/unittest/emit/InvocationTest.class.php index 17ac561f..b5ad3360 100755 --- a/src/test/php/lang/ast/unittest/emit/InvocationTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/InvocationTest.class.php @@ -1,7 +1,7 @@ =8.0")')] + #[Test, Runtime(php: '>=8.0')] public function named_arguments_in_reverse_order() { Assert::equals('html(<) = &lt;', $this->run( 'class { @@ -155,7 +155,7 @@ public function run() { )); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.0")')] + #[Test, Runtime(php: '>=8.0')] public function named_arguments_omitting_one() { Assert::equals('html(<) = <', $this->run( 'class { diff --git a/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php b/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php index d118bb24..206f9265 100755 --- a/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php @@ -2,8 +2,8 @@ use lang\ast\Errors; use lang\ast\nodes\{ClosureExpression, LambdaExpression}; -use unittest\actions\VerifyThat; -use unittest\{Action, Assert, Expect, Test}; +use test\verify\Condition; +use test\{Action, Assert, Expect, Test}; /** * Lambdas (a.k.a. arrow functions) support @@ -48,7 +48,7 @@ public function run() { Assert::equals(3, $r(1)); } - #[Test, Action(eval: 'new VerifyThat(fn() => property_exists(LambdaExpression::class, "static"))')] + #[Test, Condition(assert: 'fn() => property_exists(LambdaExpression::class, "static")')] public function static_fn_does_not_capture_this() { $r= $this->run('class { public function run() { @@ -59,7 +59,7 @@ public function run() { Assert::false($r()); } - #[Test, Action(eval: 'new VerifyThat(fn() => property_exists(ClosureExpression::class, "static"))')] + #[Test, Condition(assert: 'fn() => property_exists(ClosureExpression::class, "static")')] public function static_function_does_not_capture_this() { $r= $this->run('class { public function run() { diff --git a/src/test/php/lang/ast/unittest/emit/LoopsTest.class.php b/src/test/php/lang/ast/unittest/emit/LoopsTest.class.php index ff8d74fa..ecba2112 100755 --- a/src/test/php/lang/ast/unittest/emit/LoopsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/LoopsTest.class.php @@ -1,6 +1,6 @@ param('$param')->getType()); } - #[Test, Values('special')] + #[Test, Values(from: 'special')] public function with_special_type($declaration, $type) { Assert::equals($type, $this->param($declaration)->getType()); } @@ -73,7 +73,7 @@ public function nullable_string_type() { Assert::equals($this->nullable(Primitive::$STRING), $this->param('?string $param')->getType()); } - #[Test, Action(eval: 'new RuntimeVersion(">=7.1")')] + #[Test, Runtime(php: '>=7.1')] public function nullable_string_type_restriction() { Assert::equals($this->nullable(Primitive::$STRING), $this->param('?string $param')->getTypeRestriction()); } diff --git a/src/test/php/lang/ast/unittest/emit/PrecedenceTest.class.php b/src/test/php/lang/ast/unittest/emit/PrecedenceTest.class.php index b89c1c72..27bf9b57 100755 --- a/src/test/php/lang/ast/unittest/emit/PrecedenceTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/PrecedenceTest.class.php @@ -1,6 +1,6 @@ newInstance('Test')->fixture); } - #[Test, Values('modifiers')] + #[Test, Values(from: 'modifiers')] public function reading_from_class($modifiers) { $t= $this->type('class { public function __construct('.$modifiers.' readonly string $fixture) { } @@ -99,7 +99,7 @@ public function __construct(protected readonly string $fixture) { } Assert::equals('Test', $i->run()); } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access protected property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot access protected property .+fixture/')] public function cannot_read_protected() { $t= $this->type('class { public function __construct(protected readonly string $fixture) { } @@ -107,7 +107,7 @@ public function __construct(protected readonly string $fixture) { } $t->newInstance('Test')->fixture; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access protected property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot access protected property .+fixture/')] public function cannot_write_protected() { $t= $this->type('class { public function __construct(protected readonly string $fixture) { } @@ -115,7 +115,7 @@ public function __construct(protected readonly string $fixture) { } $t->newInstance('Test')->fixture= 'Modified'; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access private property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot access private property .+fixture/')] public function cannot_read_private() { $t= $this->type('class { public function __construct(private readonly string $fixture) { } @@ -123,7 +123,7 @@ public function __construct(private readonly string $fixture) { } $t->newInstance('Test')->fixture; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access private property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot access private property .+fixture/')] public function cannot_write_private() { $t= $this->type('class { public function __construct(private readonly string $fixture) { } @@ -151,7 +151,7 @@ public function can_be_assigned_via_reflection() { Assert::equals('Test', $i->fixture); } - #[Test, Expect(class: Error::class, withMessage: '/Cannot initialize readonly property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot initialize readonly property .+fixture/')] public function cannot_initialize_from_outside() { $t= $this->type('class { public readonly string $fixture; @@ -159,7 +159,7 @@ public function cannot_initialize_from_outside() { $t->newInstance()->fixture= 'Test'; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot modify readonly property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot modify readonly property .+fixture/')] public function cannot_be_set_after_initialization() { $t= $this->type('class { public function __construct(public readonly string $fixture) { } @@ -174,13 +174,13 @@ public function cannot_have_an_initial_value() { }'); } - #[Test, Expect(class: Error::class, withMessage: '/Cannot create dynamic property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot create dynamic property .+fixture/')] public function cannot_read_dynamic_members_from_readonly_classes() { $t= $this->type('readonly class { }'); $t->newInstance()->fixture; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot create dynamic property .+fixture/')] + #[Test, Expect(class: Error::class, message: '/Cannot create dynamic property .+fixture/')] public function cannot_write_dynamic_members_from_readonly_classes() { $t= $this->type('readonly class { }'); $t->newInstance()->fixture= true; diff --git a/src/test/php/lang/ast/unittest/emit/ReflectionTest.class.php b/src/test/php/lang/ast/unittest/emit/ReflectionTest.class.php index eb279197..e03fa8ff 100755 --- a/src/test/php/lang/ast/unittest/emit/ReflectionTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/ReflectionTest.class.php @@ -1,9 +1,9 @@ rewriteEnumCase('EMPTY')); } - #[Test, Action(eval: 'new RuntimeVersion("<8.1")')] + #[Test, Runtime(php: '<8.1')] public function rewrites_simulated_unit_enums() { $spec= ['kind' => 'class', 'extends' => null, 'implements' => [\UnitEnum::class], 'use' => []]; $t= ClassLoader::defineType('ReflectionTestSimulatedEnum', $spec, '{ @@ -58,7 +58,7 @@ static function __static() { Assert::false($reflect->rewriteEnumCase('EMPTY')); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.1")')] + #[Test, Runtime(php: '>=8.1')] public function does_not_rewrite_native_enums() { $spec= ['kind' => 'enum', 'extends' => null, 'implements' => [], 'use' => []]; $t= ClassLoader::defineType('ReflectionTestNativeEnum', $spec, '{ diff --git a/src/test/php/lang/ast/unittest/emit/ReturnTest.class.php b/src/test/php/lang/ast/unittest/emit/ReturnTest.class.php index d15ddf3b..6b1ed68b 100755 --- a/src/test/php/lang/ast/unittest/emit/ReturnTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/ReturnTest.class.php @@ -1,6 +1,6 @@ emit('$greeting= hello() world()'); } - #[Test, Expect(class: Errors::class, withMessage: 'Unexpected :')] + #[Test, Expect(class: Errors::class, message: 'Unexpected :')] public function unexpected_colon() { $this->emit('$greeting= hello();:'); } - #[Test, Expect(class: IllegalStateException::class, withMessage: 'Unexpected operator = at line 1')] + #[Test, Expect(class: IllegalStateException::class, message: 'Unexpected operator = at line 1')] public function operator() { $this->emit('=;'); } -} +} \ No newline at end of file diff --git a/src/test/php/lang/ast/unittest/emit/TernaryTest.class.php b/src/test/php/lang/ast/unittest/emit/TernaryTest.class.php index 7bffb2a7..b397dd06 100755 --- a/src/test/php/lang/ast/unittest/emit/TernaryTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/TernaryTest.class.php @@ -1,7 +1,7 @@ getMethod('noLongerSpinning')->invoke($instance)); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.2.0-dev")')] + #[Test, Runtime(php: '>=8.2.0-dev')] public function can_have_constants() { $t= $this->type('trait { const FIXTURE = 1; }'); Assert::equals(1, $t->getConstant('FIXTURE')); diff --git a/src/test/php/lang/ast/unittest/emit/TransformationsTest.class.php b/src/test/php/lang/ast/unittest/emit/TransformationsTest.class.php index a55e33df..8dc2f47f 100755 --- a/src/test/php/lang/ast/unittest/emit/TransformationsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/TransformationsTest.class.php @@ -3,7 +3,7 @@ use lang\ast\Code; use lang\ast\nodes\{Method, Signature}; use lang\ast\types\IsLiteral; -use unittest\{Assert, Before, Test, Values}; +use test\{Assert, Before, Test, Values}; class TransformationsTest extends EmittingTest { diff --git a/src/test/php/lang/ast/unittest/emit/TypeDeclarationTest.class.php b/src/test/php/lang/ast/unittest/emit/TypeDeclarationTest.class.php index 508167cb..b88813ac 100755 --- a/src/test/php/lang/ast/unittest/emit/TypeDeclarationTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/TypeDeclarationTest.class.php @@ -2,7 +2,7 @@ use lang\XPClass; use lang\reflect\Modifiers; -use unittest\{Assert, Test, Values}; +use test\{Assert, Test, Values}; class TypeDeclarationTest extends EmittingTest { diff --git a/src/test/php/lang/ast/unittest/emit/UnicodeEscapesTest.class.php b/src/test/php/lang/ast/unittest/emit/UnicodeEscapesTest.class.php index d0c21758..2ade1e33 100755 --- a/src/test/php/lang/ast/unittest/emit/UnicodeEscapesTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/UnicodeEscapesTest.class.php @@ -1,6 +1,6 @@ =8.0.0-dev")')] + #[Test, Runtime(php: '>=8.0.0-dev')] public function nullable_union_type_restriction() { $t= $this->type('class { public function test(): int|string|null { } @@ -83,7 +83,7 @@ public function test(): int|string|null { } ); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.0.0-dev")')] + #[Test, Runtime(php: '>=8.0.0-dev')] public function parameter_type_restriction_with_php8() { $t= $this->type('class { public function test(int|string|array $arg) { } @@ -95,7 +95,7 @@ public function test(int|string|array $arg) { } ); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.0.0-dev")')] + #[Test, Runtime(php: '>=8.0.0-dev')] public function parameter_function_type_restriction_with_php8() { $t= $this->type('class { public function test(): string|(function(): string) { } @@ -107,7 +107,7 @@ public function test(): string|(function(): string) { } ); } - #[Test, Action(eval: 'new RuntimeVersion(">=8.0.0-dev")')] + #[Test, Runtime(php: '>=8.0.0-dev')] public function return_type_restriction_with_php8() { $t= $this->type('class { public function test(): int|string|array { } diff --git a/src/test/php/lang/ast/unittest/emit/UsingTest.class.php b/src/test/php/lang/ast/unittest/emit/UsingTest.class.php index 0dc7e0d5..fd382d29 100755 --- a/src/test/php/lang/ast/unittest/emit/UsingTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/UsingTest.class.php @@ -1,6 +1,6 @@ getField('value')->getModifiers()); } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access private property .+::\\$value/')] + #[Test, Expect(class: Error::class, message: '/Cannot access private property .+::\\$value/')] public function cannot_read_private_field() { $t= $this->type('class { private int $value; @@ -36,7 +36,7 @@ public function cannot_read_private_field() { $t->newInstance()->value; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access private property .+::\\$value/')] + #[Test, Expect(class: Error::class, message: '/Cannot access private property .+::\\$value/')] public function cannot_write_private_field() { $t= $this->type('class { private int $value; @@ -45,7 +45,7 @@ public function cannot_write_private_field() { $t->newInstance()->value= 6100; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access protected property .+::\\$value/')] + #[Test, Expect(class: Error::class, message: '/Cannot access protected property .+::\\$value/')] public function cannot_read_protected_field() { $t= $this->type('class { protected int $value; @@ -54,7 +54,7 @@ public function cannot_read_protected_field() { $t->newInstance()->value; } - #[Test, Expect(class: Error::class, withMessage: '/Cannot access protected property .+::\\$value/')] + #[Test, Expect(class: Error::class, message: '/Cannot access protected property .+::\\$value/')] public function cannot_write_protected_field() { $t= $this->type('class { protected int $value; @@ -87,7 +87,7 @@ public function initial_value_available_via_reflection() { Assert::equals(6100, $t->getField('value')->setAccessible(true)->get($t->newInstance())); } - #[Test, Values([[null], ['Test'], [[]]]), Expect(class: Error::class, withMessage: '/property .+::\$value of type int/')] + #[Test, Values([[null], ['Test'], [[]]]), Expect(class: Error::class, message: '/property .+::\$value of type int/')] public function type_checked_at_runtime($in) { $this->run('class { private int $value; diff --git a/src/test/php/lang/ast/unittest/emit/YieldTest.class.php b/src/test/php/lang/ast/unittest/emit/YieldTest.class.php index 1ba186aa..6214402c 100755 --- a/src/test/php/lang/ast/unittest/emit/YieldTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/YieldTest.class.php @@ -1,6 +1,6 @@ getSimpleName()); } - #[Test, Expect(class: ClassFormatException::class, withMessage: 'Compiler error: Expected "type name", have "(end)"')] + #[Test, Expect(class: ClassFormatException::class, message: 'Compiler error: Expected "type name", have "(end)"')] public function load_class_with_syntax_errors() { $this->compile(['Errors' => "loadClass($types['Errors']); }); } - #[Test, Action(eval: 'new RuntimeVersion(">=7.3")'), Expect(class: ClassFormatException::class, withMessage: '/Compiler error: Class .+ not found/')] + #[Test, Runtime(php: '>=7.3'), Expect(class: ClassFormatException::class, message: '/Compiler error: Class .+ not found/')] public function load_class_with_non_existant_parent() { $code= "compile(['Orphan' => $code], function($loader, $types) { From 21aa543c25f35121705daef31f4b6557c23a16e6 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Fri, 3 Feb 2023 22:29:17 +0100 Subject: [PATCH 2/5] QA: Simplify #[Condition] --- src/test/php/lang/ast/unittest/emit/EnumTest.class.php | 2 +- src/test/php/lang/ast/unittest/emit/LambdasTest.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/php/lang/ast/unittest/emit/EnumTest.class.php b/src/test/php/lang/ast/unittest/emit/EnumTest.class.php index 6d99c994..9c5019e5 100755 --- a/src/test/php/lang/ast/unittest/emit/EnumTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/EnumTest.class.php @@ -5,7 +5,7 @@ use test\verify\Condition; use test\{Action, Assert, Expect, Ignore, Test, Values}; -#[Condition(assert: 'fn() => function_exists("enum_exists")')] +#[Condition(assert: 'function_exists("enum_exists")')] class EnumTest extends EmittingTest { #[Test] diff --git a/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php b/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php index 206f9265..8a0a1db0 100755 --- a/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/LambdasTest.class.php @@ -48,7 +48,7 @@ public function run() { Assert::equals(3, $r(1)); } - #[Test, Condition(assert: 'fn() => property_exists(LambdaExpression::class, "static")')] + #[Test, Condition(assert: 'property_exists(LambdaExpression::class, "static")')] public function static_fn_does_not_capture_this() { $r= $this->run('class { public function run() { @@ -59,7 +59,7 @@ public function run() { Assert::false($r()); } - #[Test, Condition(assert: 'fn() => property_exists(ClosureExpression::class, "static")')] + #[Test, Condition(assert: 'property_exists(ClosureExpression::class, "static")')] public function static_function_does_not_capture_this() { $r= $this->run('class { public function run() { From a3aae9c11133aab60506d94c819066d001d07e1b Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 5 Feb 2023 21:28:26 +0100 Subject: [PATCH 3/5] Use patterns for expected exceptions --- .../lang/ast/unittest/emit/ArgumentPromotionTest.class.php | 2 +- .../php/lang/ast/unittest/emit/SyntaxErrorsTest.class.php | 6 +++--- .../ast/unittest/loader/CompilingClassLoaderTest.class.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/php/lang/ast/unittest/emit/ArgumentPromotionTest.class.php b/src/test/php/lang/ast/unittest/emit/ArgumentPromotionTest.class.php index 05925b71..cbe3700b 100755 --- a/src/test/php/lang/ast/unittest/emit/ArgumentPromotionTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/ArgumentPromotionTest.class.php @@ -83,7 +83,7 @@ public function __construct(private int $id, private string $name) { } ); } - #[Test, Expect(class: Errors::class, message: 'Variadic parameters cannot be promoted')] + #[Test, Expect(class: Errors::class, message: '/Variadic parameters cannot be promoted/')] public function variadic_parameters_cannot_be_promoted() { $this->type('class { public function __construct(private string... $in) { } diff --git a/src/test/php/lang/ast/unittest/emit/SyntaxErrorsTest.class.php b/src/test/php/lang/ast/unittest/emit/SyntaxErrorsTest.class.php index e96b2e1a..d6b3836d 100755 --- a/src/test/php/lang/ast/unittest/emit/SyntaxErrorsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/SyntaxErrorsTest.class.php @@ -6,17 +6,17 @@ class SyntaxErrorsTest extends EmittingTest { - #[Test, Expect(class: Errors::class, message: 'Missing semicolon after assignment statement')] + #[Test, Expect(class: Errors::class, message: '/Missing semicolon after assignment statement/')] public function missing_semicolon() { $this->emit('$greeting= hello() world()'); } - #[Test, Expect(class: Errors::class, message: 'Unexpected :')] + #[Test, Expect(class: Errors::class, message: '/Unexpected :/')] public function unexpected_colon() { $this->emit('$greeting= hello();:'); } - #[Test, Expect(class: IllegalStateException::class, message: 'Unexpected operator = at line 1')] + #[Test, Expect(class: IllegalStateException::class, message: '/Unexpected operator =/')] public function operator() { $this->emit('=;'); } diff --git a/src/test/php/lang/ast/unittest/loader/CompilingClassLoaderTest.class.php b/src/test/php/lang/ast/unittest/loader/CompilingClassLoaderTest.class.php index 9f66aa3f..598c8f9d 100755 --- a/src/test/php/lang/ast/unittest/loader/CompilingClassLoaderTest.class.php +++ b/src/test/php/lang/ast/unittest/loader/CompilingClassLoaderTest.class.php @@ -131,7 +131,7 @@ public function load_uri() { Assert::equals('Tests', $class->getSimpleName()); } - #[Test, Expect(class: ClassFormatException::class, message: 'Compiler error: Expected "type name", have "(end)"')] + #[Test, Expect(class: ClassFormatException::class, message: '/Compiler error: Expected "type name", have .+/')] public function load_class_with_syntax_errors() { $this->compile(['Errors' => "loadClass($types['Errors']); From 6b58e9ca88a6082f4458c65229bb8c4f394f4af3 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Tue, 7 Feb 2023 21:13:27 +0100 Subject: [PATCH 4/5] Support `--output=ast,code` on command line --- src/test/php/lang/ast/unittest/emit/EmittingTest.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/php/lang/ast/unittest/emit/EmittingTest.class.php b/src/test/php/lang/ast/unittest/emit/EmittingTest.class.php index fc279114..1f107045 100755 --- a/src/test/php/lang/ast/unittest/emit/EmittingTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/EmittingTest.class.php @@ -5,9 +5,10 @@ use lang\ast\emit\GeneratedCode; use lang\ast\emit\php\XpMeta; use lang\ast\{CompilingClassLoader, Emitter, Language, Result, Tokens}; -use test\{After, Assert, TestCase}; +use test\{Args, After, Assert, TestCase}; use util\cmd\Console; +#[Args(['output' => null])] abstract class EmittingTest { private static $id= 0; private $cl, $language, $emitter, $output; From 37569bdb67201b53a6f50c5fd39fffa1f8cbd7f9 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 11 Feb 2023 12:21:55 +0100 Subject: [PATCH 5/5] Use xp-framework/test release version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2be195bd..83462d56 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "php" : ">=7.0.0" }, "require-dev" : { - "xp-framework/test": "dev-main" + "xp-framework/test": "^1.0" }, "bin": ["bin/xp.xp-framework.compiler.compile", "bin/xp.xp-framework.compiler.ast"], "autoload" : {