Skip to content
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

Test UserNotes\Sorter #606

Merged
merged 9 commits into from
Jul 5, 2022
Merged

Test UserNotes\Sorter #606

merged 9 commits into from
Jul 5, 2022

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jul 3, 2022

We add a copy of the latest run-tests.php from the PHP-8.0 branch, and
tests for the UserNotes\Sorter with full code coverage.

We add a copy of the latest run-tests.php from the PHP-8.0 branch, and
tests for the `UserNotes\Sorter` with full code coverage.
@cmb69 cmb69 mentioned this pull request Jul 3, 2022
@localheinz
Copy link
Contributor

@cmb69

How about running these tests on GitHub Actions?

See cmb69#1 and localheinz#3.

@cmb69
Copy link
Member Author

cmb69 commented Jul 3, 2022

How about running these tests on GitHub Actions?

Yes, by all means! I didn't set up CI, because I saw PR #605, so wasn't quite sure.

@localheinz
Copy link
Contributor

@cmb69

Closed #605 and adjusted cmb69#1!

@cmb69 cmb69 requested a review from kamil-tekiela July 3, 2022 14:40
@kamil-tekiela
Copy link
Member

@cmb69

I am getting test failures:

TEST 1/3 [D:\projects\web-php\tests\sort_notes_001.phpt]
========DIFF========
--
         ["total"]=>
         int(17)
         ["rating"]=>
015+     float(0.8235294117647058)
015-     float(0.82352941176471)
         ["sort"]=>
017+     float(87.41176470588235)
017-     float(87.411764705882)
       }
       [3]=>
       array(7) {
--
         ["total"]=>
         int(17)
         ["rating"]=>
032+     float(0.8235294117647058)
032-     float(0.82352941176471)
         ["sort"]=>
034+     float(87.41176470588235)
034-     float(87.411764705882)
       }
       [1]=>
       array(7) {
--
         ["rating"]=>
         float(0.5)
         ["sort"]=>
051+     float(45.49231350387337)
051-     float(45.492313503873)
       }
       [0]=>
       array(7) {
--
         float(43.4)
       }
     }
071+ 
072+ Termsig=-1073741819
========DONE========
FAIL sort some notes [D:\projects\web-php\tests\sort_notes_001.phpt]
TEST 2/3 [D:\projects\web-php\tests\sort_notes_002.phpt]
========DIFF========
     array(0) {
     }
003+ 
004+ Termsig=-1073741819
========DONE========
FAIL sort no notes [D:\projects\web-php\tests\sort_notes_002.phpt]
TEST 3/3 [D:\projects\web-php\tests\sort_notes_003.phpt]
========DIFF========
--
         float(41.4)
       }
     }
020+ 
021+ Termsig=-1073741819
========DONE========
FAIL sort a single note with no votes [D:\projects\web-php\tests\sort_notes_003.phpt]
=====================================================================
TIME END 2022-07-03 14:50:29

Any idea what I am doing wrong?

@localheinz
Copy link
Contributor

@kamil-tekiela

Which PHP version are you using?

@kamil-tekiela
Copy link
Member

PHP 8.0.3 (cli) (built: Mar 2 2021 23:34:05) ( ZTS Visual C++ 2019 x64 )

@localheinz
Copy link
Contributor

@kamil-tekiela

I'm getting similar test failures on

  • PHP 8.0.16
  • PHP 8.1.3

Looks like something changed in regard to the precision.

@localheinz
Copy link
Contributor

localheinz commented Jul 3, 2022

@cmb69

Is there a way to run the tests without producing any files on failure?

@localheinz
Copy link
Contributor

@cmb69

How do you feel about moving the tests?

diff --git a/tests/sort_notes_001.phpt b/tests/UserNotes/Sorter/sort_notes_001.phpt
similarity index 96%
rename from tests/sort_notes_001.phpt
rename to tests/UserNotes/Sorter/sort_notes_001.phpt
index adc07611..e9bfac6e 100644
--- a/tests/sort_notes_001.phpt
+++ b/tests/UserNotes/Sorter/sort_notes_001.phpt
@@ -2,7 +2,7 @@
 sort some notes
 --FILE--
 <?php
-require_once __DIR__ . "/../src/UserNotes/Sorter.php";
+require_once __DIR__ . "/../../src/UserNotes/Sorter.php";

 $notes = [
     [
diff --git a/tests/sort_notes_002.phpt b/tests/UserNotes/Sorter/sort_notes_002.phpt
similarity index 89%
rename from tests/sort_notes_002.phpt
rename to tests/UserNotes/Sorter/sort_notes_002.phpt
index def6d4b1..51387dcb 100644
--- a/tests/sort_notes_002.phpt
+++ b/tests/UserNotes/Sorter/sort_notes_002.phpt
@@ -2,7 +2,7 @@
 sort no notes
 --FILE--
 <?php
-require_once __DIR__ . "/../src/UserNotes/Sorter.php";
+require_once __DIR__ . "/../../src/UserNotes/Sorter.php";

 $notes = [];

diff --git a/tests/sort_notes_003.phpt b/tests/UserNotes/Sorter/sort_notes_003.phpt
similarity index 93%
rename from tests/sort_notes_003.phpt
rename to tests/UserNotes/Sorter/sort_notes_003.phpt
index 9e088464..c03af237 100644
--- a/tests/sort_notes_003.phpt
+++ b/tests/UserNotes/Sorter/sort_notes_003.phpt
@@ -2,7 +2,7 @@
 sort a single note with no votes
 --FILE--
 <?php
-require_once __DIR__ . "/../src/UserNotes/Sorter.php";
+require_once __DIR__ . "/../../src/UserNotes/Sorter.php";

 $notes = [
     [

@cmb69
Copy link
Member Author

cmb69 commented Jul 3, 2022

Looks like something changed in regard to the precision.

Yeah, I actually expected this; var_dump() uses serialize_precision rather than precision as of PHP 8.0.0. This can be fixed by adding a respective entry to an --INI-- section.

But I'm more concerned about

072+ Termsig=-1073741819

That is a segfault (aka. access violation on Windows). Maybe it is "just" the old revision (8.0.3).

Is there a way to run the tests without producing any files on failure?

I don't think so, but there are

--temp-source --temp-target [--temp-urlbase ]
Write temporary files to by replacing from the
filenames to generate with . In general you want to make
the path to your source files and some patch in
your web page hierarchy with pointing to .

How do you feel about moving the tests?

I think this is a good idea. The basenames could then be shorted: sort_001.phpt etc. Or maybe use more self explaining basenames instead: sort_some.php, sort_no.phpt and sort_without_votes.phpt or so.

@kamil-tekiela
Copy link
Member

FWIW with 8.1.4 I only get precision errors and no segfaults. I don't have any other PHP 8.0 version installed at the moment, but maybe I will download a newer one and test again

We also adjust the test expectations.
@cmb69
Copy link
Member Author

cmb69 commented Jul 3, 2022

@kamil-tekiela, I just pushed a commit which is supposed to resolve the precision issue.

@kamil-tekiela
Copy link
Member

PHP 7.4 - I get some completely different output.
PHP 8.0 - I get 3 segfaults
PHP 8.1 - All pass

@cmb69
Copy link
Member Author

cmb69 commented Jul 3, 2022

PHP 7.4 - I get some completely different output.

The current tests pass for me with PHP 7.4.19 and 8.0.19 (haven't tested other versions).

@kamil-tekiela
Copy link
Member

I downloaded 8.0.20 and no more segfaults.

On PHP 7.4.9, the output is:

array(4) {
  [2] =>
  array(7) {
    'ts' =>
    int(1508179844)
    'upvotes' =>
    int(14)
    'downvotes' =>
    int(3)
    'score' =>
    int(11)
    'total' =>
    int(17)
    'rating' =>
    double(0.8)
    'sort' =>
    double(9.0E+1)
  }
  [3] =>
  array(7) {
    'ts' =>
    int(1508179844)
    'upvotes' =>
    int(14)
    'downvotes' =>
    int(3)
    'score' =>
    int(11)
    'total' =>
    int(17)
    'rating' =>
    double(0.8)
    'sort' =>
    double(9.0E+1)
  }
  [1] =>
  array(7) {
    'ts' =>
    int(1508180150)
    'upvotes' =>
    int(0)
    'downvotes' =>
    int(0)
    'score' =>
    int(0)
    'total' =>
    int(0)
    'rating' =>
    double(0.5)
    'sort' =>
    double(5.0E+1)
  }
  [0] =>
  array(7) {
    'ts' =>
    int(1613487094)
    'upvotes' =>
    int(0)
    'downvotes' =>
    int(2)
    'score' =>
    int(-2)
    'total' =>
    int(2)
    'rating' =>
    int(0)
    'sort' =>
    double(4.0E+1)
  }
}

@cmb69
Copy link
Member Author

cmb69 commented Jul 3, 2022

On PHP 7.4.9, the output is:

I get these results with precision=1, but that setting should be changed by the tests to precision=-1.

Fix: Run build on PHP 7.3 instead of PHP 7.2
cmb69 and others added 3 commits July 5, 2022 12:20
Co-authored-by: Andreas Möller <[email protected]>
Co-authored-by: Andreas Möller <[email protected]>
Co-authored-by: Andreas Möller <[email protected]>
Copy link
Contributor

@localheinz localheinz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about GH actions to judge if it's correct, but the rest looks fine to me.

@cmb69
Copy link
Member Author

cmb69 commented Jul 5, 2022

Well, then let's merge this; we can still improve the GH action integration if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants