-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(test): exit code of lime test #301
base: master
Are you sure you want to change the base?
fix(test): exit code of lime test #301
Conversation
f4f102e
to
46a8d60
Compare
46a8d60
to
a60ff02
Compare
a60ff02
to
05ac333
Compare
05ac333
to
154bc18
Compare
Rebased on master branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch is also included in #302, isn't it?
154bc18
to
136b3c1
Compare
lib/vendor/lime/lime.php
Outdated
@@ -155,6 +161,31 @@ public function __destruct() | |||
} | |||
|
|||
flush(); | |||
|
|||
self::$allExitCode |= $this->getExitCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a binary operation, done on an integer value, we should cast it to a bool before, or rename getExitCode()
to isTestFailed()
WDYT?
lib/vendor/lime/lime.php
Outdated
@@ -24,9 +24,13 @@ class lime_test | |||
protected $options = array(); | |||
|
|||
static protected $all_results = array(); | |||
static private $instanceCount = 0; | |||
static private $allExitCode = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about $overallSuccessful = true
?
lib/vendor/lime/lime.php
Outdated
$plan = $this->results['stats']['plan']; | ||
$failed = count($this->results['stats']['failed']); | ||
$total = $this->results['stats']['total']; | ||
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rewrite this as an if
statement?
lib/vendor/lime/lime.php
Outdated
if ($failed) | ||
{ | ||
return 1; | ||
} | ||
else if ($total == $plan) | ||
{ | ||
return 0; | ||
} | ||
|
||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($failed) | |
{ | |
return 1; | |
} | |
else if ($total == $plan) | |
{ | |
return 0; | |
} | |
return 1; | |
if (0 !== $failed) { | |
return 1; | |
} | |
return $total == $plan ? 0 : 1; |
@thePanz thanks for your review. Mainly, your feedbacks are only about having better code structure. So I will proceed with fixing code structure. |
After rebase on $ test/bin/test
+ docker-compose build
ERROR: The Compose file is invalid because:
Service php81 has neither an image nor a build context specified. At least one must be provided. I know how to fix it. https://github.com/FriendsOfSymfony1/symfony1/blob/master/README.md?plain=1#L61-L64 |
136b3c1
to
dd6a51c
Compare
lib/vendor/lime/lime.php
Outdated
self::$allExitCode |= $this->getExitCode(); | ||
|
||
if (0 === self::$instanceCount) { | ||
exit(self::$allExitCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit(self::$allExitCode); | |
exit(self::$allExitCode); |
lib/vendor/lime/lime.php
Outdated
$plan = $this->results['stats']['plan']; | ||
$failed = count($this->results['stats']['failed']); | ||
$total = $this->results['stats']['total']; | ||
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please improve the readability of this. This line makes me think of perl or bash code before php.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is it a valuation that is a mistake? 🤔
lib/vendor/lime/lime.php
Outdated
const STATE_PASS = 0; | ||
const STATE_FAIL = 1; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add visibility.
test/bin/test
Outdated
# | ||
dependencyPreferences='highest' | ||
skipPHPVersions='php8' | ||
main () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to keep the context of the PR.
docker-compose.yml
Outdated
@@ -50,6 +50,7 @@ services: | |||
php81: | |||
<<: *services_php74 | |||
build: | |||
context: .docker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to keep the context of the PR.
fa11b69
to
f25c0cd
Compare
Return types for private methods! Nice! That's what I was thinking, that I could do it everywhere in the framework. Thank you! |
@@ -952,8 +1015,7 @@ function lime_shutdown() | |||
); | |||
|
|||
ob_start(); | |||
// see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm copying the content of the trac ticket here to keep what it was:
[PATCH] lime.php not working on windows when there are spaces in php interpreter path
lime.php, line 541
passthru(sprintf('%s "%s" 2>&1', $this->php_cli, $file), $return);
the command fails if the path to php interpreter contains spaces, this obviously prevent all test to run.
In order to work with executables in directories with spaces it should be
passthru(sprintf('"%s" "%s" 2>&1', $this->php_cli, $file), $return);
but this fails too on windows: system/exec/passthru all fail when more than two arguments are quoted (it seems a php bug but I couldn't find any reference apart from some comments on the system function page)
In order to work on windows it should be written as
passthru(sprintf('""%s" "%s"" 2>&1', $this->php_cli, $file), $return);
this works on windows but still fails on linux (note the double "double quotes": I need to quote the entire command not just the executable and the argument)
The only workaround I could find was something I found on the comments of the system function that is adding a "nop" command call before the quoted command
passthru(sprintf('cd & "%s" "%s" 2>&1', $this->php_cli, $file), $return);
f25c0cd
to
d094b34
Compare
Apart from the fact that it's red now, I'm happy with the state of it! Well done! |
It was not only about code structure, but the behavior has been exposed with the proof that work as expected (tests). The current tests that failed introduce the fact that it should treat PHP errors/warnings/... as test failure with failed status code. This failed test is like a marker to tell me what's next, for the next coding session. Now I wonder if that is it useful to expose the behavior when an As the migration to PHPUnit will make this obsolete. |
If hidden errors occur, yes. If valuable information about the state of the code is obtained, yes. If it just generates noise, no. The effects of such a change are only visible to you at the moment.
What you did was not useless, because it will take a long time to migrate all the tests under phpunit. Looking at the current tempo, an optimistic estimate is that one tenth of the tests will be moved to phpunit this year. |
d094b34
to
c8ff5bc
Compare
7e19aea
to
d943f48
Compare
The diff before class extraction https://github.com/FriendsOfSymfony1/symfony1/pull/301/files/fbc40e7396a0f0da445585c57cc2486d243d75ae |
@alquerci I agree here: the class extraction is a good thing to have, but makes this PR quite hard to follow. yes, maybe this is a "too much refactoring". WDYT? |
I propose a separate PR for cleaning, cs-fix and separation. |
To rephrase
That's a nice kata, I like it. @connorhu Should I do it? How I will do it?First PR
The code will be hard to read, but tests will pass. Second PR
OR
|
If clean code is a prerequisite for successful test execution, the PR order is: cleanup, exit code. If clean code is not a prerequisite for successful test execution: exit code, cleanup. |
@connorhu It is something between. To be able to clean the code (having a better code structure). After that a trusted test suite is in place. After that you make one small test pass Instead, start to make one small step to the new behaviour (as steps I used on this PR).
So here, I see no problem to restart the work on this. What do you think? |
Here's what we think differently about. There are many PRs that are created because we see something in the code as a cleaning, tidying up process. The fact that lime classes are placed in a file is incorrect in the current practice of symfony core. The fact that indentation is 2 spaces is actually incorrect according to the current code base of symfony core. So we need one (or two) organizer PRs that will eliminate this inconsistency. There is no need for these PRs to be created because of the "exit code" issue. If I previously notice lime using 2 space indentation I will have already cleaned it up (or added the rule to editorconfig). If you want to fix the "exit code" problem, you must do it in a way that the fix is 100% understandable and transparent (so you must do the cleanup first or last). Regardless of whether we're talking about 2-3 PRs, the end result of PRs in a row is that you have a more reliable test system, so you've achieved your goal. To me, a measure of the reliability of a change is a) the code logic is unchanged (processes that are done by programs of proven quality, e.g. rector, cs-fixer) b) the change is verified by tests. |
I am closing this PR. In order to provide a fix 100% understandable and transparent.
|
@alquerci I don't think you should close this PR. If I'm right, this is step 2 of 4. The 4 steps sketched out seem logical to me. |
Okay, @connorhu thanks for your feedback. Let's go, I will keep open this PR with force push when step 1 is done. |
1st step done |
Lime test should exit with non-zero code on failure.
Before this patch, it is not the case.