Permalink
Browse files

Replace hh_show by expect(...) in tests (1)

Summary:
The use of `hh_show` in tests is very brittle. It depends on pretty-printing; fixed points cause types to be shown more than once; and brittle position information is displayed.
Better to check that a variable has the expected type by passing it to an `expect(...)` function, which is very easy now that we have explicit generic parameters to functions.

Reviewed By: Wilfred

Differential Revision: D13178870

fbshipit-source-id: 2019c4558e157b8541ce903a15b14dc417de1d5f
  • Loading branch information...
andrewjkennedy authored and hhvm-bot committed Nov 23, 2018
1 parent d751b97 commit 34ebd5839f53fa9af9dba699d95efb2f99a8a23c
@@ -9,9 +9,11 @@
yield 42 => $x;
}
function expect<T>(T $x):void { }
async function g(): Awaitable<void> {
foreach (f() await as $x => $y) {
hh_show($x);
hh_show($y);
expect<int>($x);
expect<string>($y);
}
}
@@ -1,9 +1 @@
File "asyncgen1.php", line 14, characters 5-15:
int
File "asyncgen1.php", line 15, characters 5-15:
string
File "asyncgen1.php", line 14, characters 5-15:[2]
int
File "asyncgen1.php", line 15, characters 5-15:[2]
string
No errors
@@ -9,9 +9,11 @@ function f(): AsyncGenerator<int, string, void> {
yield 42 => $x;
}
function expect<T>(T $x): void { }
async function g(): Awaitable<void> {
foreach (f() await as $x => $y) {
hh_show($x);
hh_show($y);
expect<int>($x);
expect<string>($y);
}
}
@@ -1,10 +1,2 @@
File "asyncgen3.php", line 14, characters 5-15:
int
File "asyncgen3.php", line 15, characters 5-15:
string
File "asyncgen3.php", line 14, characters 5-15:[2]
int
File "asyncgen3.php", line 15, characters 5-15:[2]
string
File "asyncgen3.php", line 8, characters 8-18:
await can only be used inside async functions (NastCheck[3003])
@@ -8,9 +8,11 @@ function f(): AsyncGenerator<int, string, void> {
yield 42 => 'hi test';
}
function expect<T>(T $x):void { }
async function g(): Awaitable<void> {
foreach (f() await as $x => $y) {
hh_show($x);
hh_show($y);
expect<int>($x);
expect<string>($y);
}
}
@@ -1,11 +1,3 @@
File "asyncgen5.php", line 13, characters 5-15:
int
File "asyncgen5.php", line 14, characters 5-15:
string
File "asyncgen5.php", line 13, characters 5-15:[2]
int
File "asyncgen5.php", line 14, characters 5-15:[2]
string
File "asyncgen5.php", line 8, characters 3-23:
Invalid yield (Typing[4110])
File "asyncgen5.php", line 7, characters 15-47:
@@ -10,12 +10,14 @@ class C {
const int KEY2 = 2;
}
function expect<T>(T $x):void { }
function test(my_shape $s): void {
hh_show(Shapes::toArray($s));
hh_show(Shapes::toArray(shape()));
hh_show(Shapes::toArray(shape('x' => 4, 'y' => 'aaa')));
hh_show(Shapes::toArray(shape(C::KEY1 => 4, C::KEY2 => 'aaa')));
expect<darray<arraykey,mixed>>(Shapes::toArray($s));
expect<array<int,bool>>(Shapes::toArray(shape()));
expect<array<string,arraykey>>(Shapes::toArray(shape('x' => 4, 'y' => 'aaa')));
expect<array<int,arraykey>>(Shapes::toArray(shape(C::KEY1 => 4, C::KEY2 => 'aaa')));
$s = shape();
$s['x'] = 3;
hh_show(Shapes::toArray($s));
expect<array<string,int>>(Shapes::toArray($s));
}
@@ -1,11 +1 @@
File "shape_to_array.php", line 14, characters 3-30:
darray<arraykey, mixed>
File "shape_to_array.php", line 15, characters 3-35:
array<[unresolved], [unresolved]>
File "shape_to_array.php", line 16, characters 3-57:
array<string, (int | string)>
File "shape_to_array.php", line 17, characters 3-65:
array<int, (int | string)>
File "shape_to_array.php", line 20, characters 3-30:
array<string, int>
No errors
@@ -4,9 +4,11 @@ function f(): Generator<string, int, void> {
yield 'one' => 1;
}
function expect<T>(T $x): void { }
function g(): void {
foreach (f() as $k => $v) {
hh_show($k);
hh_show($v);
expect<string>($k);
expect<int>($v);
}
}
@@ -1,9 +1 @@
File "yield_kv4.php", line 9, characters 5-15:
string
File "yield_kv4.php", line 10, characters 5-15:
int
File "yield_kv4.php", line 9, characters 5-15:[2]
string
File "yield_kv4.php", line 10, characters 5-15:[2]
int
No errors

0 comments on commit 34ebd58

Please sign in to comment.