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

Import yoga tests #320

Merged
merged 17 commits into from
Jan 12, 2023
Merged

Conversation

nicoburns
Copy link
Collaborator

@nicoburns nicoburns commented Jan 5, 2023

Objective

Fixes #285.

Changes made

  • Add a re-runnable diff script that also does some munging of the test names to make them match up when they have diverged.
  • Add an import script. This is pretty rough, but I feel like standards need not be so high for something that is run "offline" and rarely. It compiles, runs, it's formatted and linted.
  • Import ALL yoga tests (including the ones from Add newer fixtures facebook/yoga#1194 that they haven't landed on master yet)

Notes

  • I have imported all tests, but I have not made any attempt to fix failing ones. I feel like this would be best tackled in follow up PRs that tackle a group of related failing tests without trying to fix everything at once, as I imagine some will be a lot more difficult than other.
  • I have also not made any attempt to diff the tests to check for differences in the specification of tests that we both have. This would also be useful thing to do, but it's a much more complex task (diffing HTML is non-trivial).

@nicoburns nicoburns marked this pull request as draft January 5, 2023 00:54
@alice-i-cecile alice-i-cecile added the build system Make continuous integration do the tedious things label Jan 5, 2023
@nicoburns nicoburns changed the title WIP: Import yoga tests Import yoga tests Jan 5, 2023
@nicoburns nicoburns force-pushed the test/import-yoga-tests branch from 7866d71 to 4b879d0 Compare January 5, 2023 14:01
@nicoburns nicoburns marked this pull request as ready for review January 5, 2023 14:01
@nicoburns nicoburns added code quality Make the code cleaner or prettier. testing Additional tests or improvements to the testing infrastructure and removed code quality Make the code cleaner or prettier. labels Jan 5, 2023
Copy link
Collaborator

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I think we should throw together a quick README.md for the impoort-yoga-tests crate, describing its purpose and instructions for getting it working.

The convention where tests that begin with an x are ignored should also be documented: at a glance, I can't figure out where this is being done.

.collect();

for fixture in yoga_fixtures {
if !taffy_fixture_names.contains(&fixture.name) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if the fixtures are updated but not renamed? Won't they get out of sync with this strategy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Won't they get out of sync with this strategy?

Yes. They likely already are. This is at least a quick way to get us tests we were entirely missing though. I guess we'll need to actually parse the HTML/CSS to sync updates.

Copy link
Collaborator

@alice-i-cecile alice-i-cecile Jan 5, 2023

Choose a reason for hiding this comment

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

Makes sense. What's the cost to rebuilding them completely every time?

(We should document this conversation in a comment if we decide to keep this behavior).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What's the cost to rebuilding them completely every time?

As in treating Yoga's version as the source of truth and overwriting any changes we might have made? There's no technical blocker on that. I think the main problem with that would be that it would make it hard for us to maintain any changes that we actually need. As an example: I removed whitespace from a couple of tests when I added support for sizing text nodes. It would be nice if there was a single source of truth though, and I suppose that could be managed by just being selective with when we sync and which changes we commit when we sync.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds reasonable: I'm fine with whatever you pick here.

@nicoburns nicoburns force-pushed the test/import-yoga-tests branch from 4b879d0 to 2e8f922 Compare January 5, 2023 18:21
@nicoburns nicoburns added this to the 0.3 milestone Jan 5, 2023
<div layout="width: 1080; height: 444; top: 0; left: 0;" style="flex-shrink: 0; " >
<div layout="width: 1080; height: 444; top: 0; left: 0;" style="align-content: stretch; " >
<div layout="width: 1080; height: 226; top: 0; left: 0;" style="align-content: stretch; " >
<div layout="width: 1044; height: 202; top: 24; left: 36;" style="flex-direction: row; align-items: flex-start; align-content: stretch; margin-top: 24px; margin-start: 36px; " >

Choose a reason for hiding this comment

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

The "margin-start" here is not a valid CSS property, and Yoga's test generator did some funky things with it. But it's effectively the same as "margin-inline-start" for any case that isn't a vertical writing direction (which I don't think Yoga or Taffy support).

Copy link

@NickGerleman NickGerleman Jan 6, 2023

Choose a reason for hiding this comment

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

That should be cleaned up soon in the Yoga source, there is a PR I had cleaned up some of these in the newer PR this imports from, but I discovered I needed to update the test generator to properly translate it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that's useful to know. Taffy actually doesn't support margin-inline-start either (it has margin-left). I'm guessing Yoga also doesn't support this and the test generator just converts it to left/right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did a test run overwriting all of Taffy's test with Yoga's (where there as an equivalent) to see what the diff would be like, and there were quite a few differences. In addition to the start/end vs. left/right thing, the main one's were due to Yoga defaulting to flex-direciton: column while Taffy defaults to flex-direction: row. Many of a Taffy's tests had an explicit flex-direction added to account for this. And some of them had width/height swapped to account for it in a different way. I suspect we'll need to add explicit flex-direction everywhere if we want to unify the test suites.

Choose a reason for hiding this comment

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

Ah, that's useful to know. Taffy actually doesn't support margin-inline-start either (it has margin-left). I'm guessing Yoga also doesn't support this and the test generator just converts it to left/right?

Yoga does have support for flow-relative margin, padding, etc. The API at the Yoga level looks like YGNodeStyleSetMargin, accepting a YGEdge, which can be (in order of precedence) a cardinal direction (e.g. YGEdgeLeft), a flow-relative direction (e.g. YGEdgeStart), an axis (e.g. YGEdgeHorizontal), or YGEdgeAll.

React Native historically historically mapped YGEdgeStart to marginStart, etc, but we recently added marginInlineStart, marginBlockStart, etc to be conformant with browsers.

Choose a reason for hiding this comment

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

Wouldn't you need a flow-relative direciton AND an axis to fully specify an edge? (YGEdgeStart by itself is ambiguous. You'd need YGEdgeInlineStart, no?).

Start/End only ever refer to the horizontal axis, and just picks Left/Right based on RTL. But yeah, the style has distinct inputs for padding, margin, etc per YGEdge, and a specific precedence when multiple inputs are present which may overlap the same physical edge. It would be reevaluated if laid out as RTL. Yoga also weirdly treats both YGEdgeLeft and YGEdgeStart as effecting the right side of a box with flexDirection: "row-reverse" which is inconsistent with browsers.

Yoga's precedence logic based on specificity is one difference from browsers, where CSS properties are ordered and if there is overlap, the last assignment wins (e.g. "margin" takes precedence over "marginLeft" if it comes after).

Copy link

@NickGerleman NickGerleman Jan 8, 2023

Choose a reason for hiding this comment

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

Perhaps it would make sense to make this the default specifically for the test suite? (updating the test fixtures accordingly so that the actual tests don't change).

I think updating that would probably make sense. If you're having to add column direction, was Yoga's test generator doing that in the outer HTML too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you're having to add column direction, was Yoga's test generator doing that in the outer HTML too?

I haven't actually checked that yet. I've gone through and added all the flex-direction: columns. But actually, all of those tests were already passing. So it's possible that the missing flex-directions weren't actually making a meaningful difference to the tests. I'd still be more comfortable if the tests are unambiguously specified though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Start/End only ever refer to the horizontal axis, and just picks Left/Right based on RTL.

Ah, I guess that makes sense given that IIRC Yoga supports RTL but not vertical writing modes. The variants are confusingly named though! I'm guessing that might the sort of thing it might be more possible to make breaking changes to (as it will turn into a compile error)?

Yoga also weirdly treats both YGEdgeLeft and YGEdgeStart as effecting the right side of a box with flexDirection: "row-reverse" which is inconsistent with browsers.

That is weird. As documented in #307, it does work that way for the flex-start alignment value, but there is also a separate start which isn't affected by the the flex-direction, and it definitely shouldn't do that for left!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you're having to add column direction, was Yoga's test generator doing that in the outer HTML too?

@NickGerleman I looked into this, and the stylesheet that Yoga uses when generating tests applies this default. See https://github.com/facebook/yoga/blob/main/gentest/test-template.html#L28

@nicoburns nicoburns added the blocked Cannot be advanced until something else changes label Jan 6, 2023
@nicoburns nicoburns force-pushed the test/import-yoga-tests branch 2 times, most recently from 9507561 to bac71f1 Compare January 7, 2023 17:54
@nicoburns nicoburns removed the blocked Cannot be advanced until something else changes label Jan 7, 2023
@nicoburns nicoburns force-pushed the test/import-yoga-tests branch 2 times, most recently from 89c8647 to 99b56ca Compare January 12, 2023 12:55
@nicoburns nicoburns added the blocked Cannot be advanced until something else changes label Jan 12, 2023
@nicoburns nicoburns mentioned this pull request Jan 12, 2023
3 tasks
@nicoburns nicoburns removed the blocked Cannot be advanced until something else changes label Jan 12, 2023
@nicoburns nicoburns force-pushed the test/import-yoga-tests branch from f5421b1 to 33b6737 Compare January 12, 2023 21:05
@nicoburns nicoburns force-pushed the test/import-yoga-tests branch from 33b6737 to 7f7b0c6 Compare January 12, 2023 21:06
@nicoburns nicoburns mentioned this pull request Jan 12, 2023
13 tasks
@nicoburns
Copy link
Collaborator Author

@alice-i-cecile Requested changes made. Filtering out tests beginning with x happens here https://github.com/DioxusLabs/taffy/blob/main/scripts/gentest/src/main.rs#L27. And the gentest script completely overwrites the generated test directory when it runs so that will also delete any already existing generated tests.

@nicoburns nicoburns force-pushed the test/import-yoga-tests branch from cb6733d to 8a139da Compare January 12, 2023 22:00
Copy link
Collaborator

@Weibye Weibye left a comment

Choose a reason for hiding this comment

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

Good work as usual! The increased test coverage is surely going to be valuable in guiding rework and new features.

scripts/import-yoga-tests/Cargo.toml Show resolved Hide resolved
test_fixtures/align_baseline_multiline_column.html Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile merged commit e05b909 into DioxusLabs:main Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system Make continuous integration do the tedious things testing Additional tests or improvements to the testing infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync generated test suite with Yoga
4 participants