Skip to content

Commit ff3026c

Browse files
committed
Assert the files the parse error tests re-analyse with result-cache-info
Amp-Thread-ID: https://ampcode.com/threads/T-01a1c5c8-8d5b-7459-a22c-beb8e7ba8a3b
1 parent c7683f3 commit ff3026c

1 file changed

Lines changed: 34 additions & 25 deletions

File tree

‎e2e/result-cache-parse-error/result-cache-parse-error_test.sh‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,58 @@ function test_result_cache_parse_error() {
3636
}
3737

3838
function test_result_cache_parse_error_keeps_symbols() {
39-
# A warm result cache without the parse error, and src/Other.php with an error, which makes
40-
# it one of the files that are re-analysed when a symbol appears or disappears.
39+
# A warm result cache without the parse error. src/User.php uses Thing, and src/Other.php has
40+
# an error, which makes it one of the files re-analysed when a symbol appears or disappears.
4141
cp src/Thing.php "$TMPDIR/BrokenThing.php"
4242
cp fixed/Thing.php src/Thing.php
4343
printf '<?php declare(strict_types = 1);\n\nnamespace ResultCacheE2EParseError;\n\nfunction doOther(): int\n{\n\treturn "other";\n}\n' > src/Other.php
44-
../../bin/phpstan analyse --error-format raw > /dev/null 2>&1 || true
45-
# Breaking src/Thing.php re-analyses only it: src/User.php keeps its result.
44+
../../bin/phpstan analyse > /dev/null 2>&1 || true
45+
# Breaking src/Thing.php re-analyses only it, not src/User.php and src/Other.php.
4646
cp "$TMPDIR/BrokenThing.php" src/Thing.php
47-
OUTPUT=$(../../bin/phpstan analyse -vvv --error-format raw 2>&1) && CODE=0 || CODE=$?
47+
INFO=$(../../bin/phpstan result-cache-info --json)
48+
echo "$INFO"
49+
assert_equals 'true' "$(echo "$INFO" | jq --raw-output '.resultCacheUsed')"
50+
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
51+
OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && CODE=0 || CODE=$?
4852
assert_same "1" "$CODE"
4953
echo "$OUTPUT"
50-
assert_contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
5154
assert_contains 'Thing.php:12:Syntax error, unexpected EOF on line 12' "$OUTPUT"
52-
# The first run had nothing to save, so the next one records the file stat of src/Thing.php,
53-
# and the cache is not rewritten after that.
54-
../../bin/phpstan analyse --error-format raw > /dev/null 2>&1 || true
55-
OUTPUT=$(../../bin/phpstan analyse -vvv --error-format raw 2>&1) && CODE=0 || CODE=$?
56-
assert_same "1" "$CODE"
57-
echo "$OUTPUT"
58-
assert_contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
59-
assert_contains 'Result cache was not rewritten because it is unchanged.' "$OUTPUT"
60-
# Fixing it declares the same symbols as before, so nothing else is re-analysed either.
55+
# Saving it broken differently does not either.
56+
printf '\n// still broken\n' >> src/Thing.php
57+
INFO=$(../../bin/phpstan result-cache-info --json)
58+
echo "$INFO"
59+
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
60+
../../bin/phpstan analyse > /dev/null 2>&1 || true
61+
# Fixing it declares the same symbols as before it broke, so it is re-analysed alone too.
6162
cp fixed/Thing.php src/Thing.php
62-
OUTPUT=$(../../bin/phpstan analyse -vvv --error-format raw 2>&1) && CODE=0 || CODE=$?
63-
assert_same "1" "$CODE"
63+
INFO=$(../../bin/phpstan result-cache-info --json)
64+
echo "$INFO"
65+
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
66+
OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && CODE=0 || CODE=$?
6467
echo "$OUTPUT"
65-
assert_contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
66-
assert_not_contains 'Syntax error' "$OUTPUT"
68+
rm -rf tmp/resultCache.php
69+
COLD_OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && COLD_CODE=0 || COLD_CODE=$?
70+
echo "$COLD_OUTPUT"
71+
assert_same "$COLD_CODE" "$CODE"
72+
assert_same "$COLD_OUTPUT" "$OUTPUT"
6773
assert_contains 'Other.php:7:Function ResultCacheE2EParseError\doOther() should return int but returns string.' "$OUTPUT"
6874
}
6975

7076
function test_result_cache_parse_error_file_analysed_meanwhile() {
7177
cp src/Thing.php "$TMPDIR/BrokenThing.php"
7278
cp fixed/Thing.php src/Thing.php
73-
../../bin/phpstan analyse --error-format raw > /dev/null 2>&1 || true
79+
../../bin/phpstan analyse > /dev/null 2>&1 || true
7480
cp "$TMPDIR/BrokenThing.php" src/Thing.php
75-
../../bin/phpstan analyse --error-format raw > /dev/null 2>&1 || true
76-
# src/NewUser.php is analysed while src/Thing.php declares nothing, so it finds Thing missing,
77-
# and it has to be analysed again once src/Thing.php is fixed, even though its symbols are the
78-
# same as before it broke.
81+
../../bin/phpstan analyse > /dev/null 2>&1 || true
82+
# src/NewUser.php is analysed while src/Thing.php declares nothing, so it finds Thing missing.
7983
printf '<?php declare(strict_types = 1);\n\nnamespace ResultCacheE2EParseError;\n\nfunction doNewUser(): string\n{\n\treturn (new Thing())->doThing();\n}\n' > src/NewUser.php
80-
../../bin/phpstan analyse --error-format raw > /dev/null 2>&1 || true
84+
../../bin/phpstan analyse > /dev/null 2>&1 || true
85+
# Fixing src/Thing.php makes its symbols appear again even though they are the same as before
86+
# it broke: it is re-analysed with src/User.php using it and src/NewUser.php, which has an error.
8187
cp fixed/Thing.php src/Thing.php
88+
INFO=$(../../bin/phpstan result-cache-info --json)
89+
echo "$INFO"
90+
assert_equals '3' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
8291
OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && CODE=0 || CODE=$?
8392
echo "$OUTPUT"
8493
rm -rf tmp/resultCache.php

0 commit comments

Comments
 (0)