From 98125f304070024dbb0188aefaa45712070d124f Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Wed, 18 Sep 2024 16:02:35 +0200 Subject: [PATCH] tools: Initial reftests implementation. --- .gitignore | 3 +- {tests => dev}/borders/borders-test.xhtml | 0 {tests => dev}/borders/borders.xhtml | 0 {tests => dev}/flex/disclone.xhtml | 0 {tests => dev}/inline/history.html | 0 {tests => dev}/inline/the-project.html | 0 .../media-queries/red-or-blue.xhtml | 0 {tests => dev}/normal-flow/normal-flow.xhtml | 0 {tests => dev}/normal-flow/red-square.xhtml | 0 {tests => dev}/tables/ledger.css | 0 {tests => dev}/tables/ledger.xhtml | 0 {tests => dev}/tables/mini-ledger.xhtml | 0 {tests => dev}/tables/table-borders.xhtml | 0 {tests => dev}/tables/table.xhtml | 0 meta/plugins/__init__.py | 5 + meta/plugins/reftest.py | 40 ++++++ meta/plugins/requirements.txt | 2 +- meta/targets/host-any.json | 5 +- src/vendors/libs/karm-io/pack.h | 3 +- tests/css/.ref/cascade.xhtml.ref | 132 ++++++++++++++++++ tests/css/cascade.xhtml | 24 ++++ 21 files changed, 208 insertions(+), 6 deletions(-) rename {tests => dev}/borders/borders-test.xhtml (100%) rename {tests => dev}/borders/borders.xhtml (100%) rename {tests => dev}/flex/disclone.xhtml (100%) rename {tests => dev}/inline/history.html (100%) rename {tests => dev}/inline/the-project.html (100%) rename {tests => dev}/media-queries/red-or-blue.xhtml (100%) rename {tests => dev}/normal-flow/normal-flow.xhtml (100%) rename {tests => dev}/normal-flow/red-square.xhtml (100%) rename {tests => dev}/tables/ledger.css (100%) rename {tests => dev}/tables/ledger.xhtml (100%) rename {tests => dev}/tables/mini-ledger.xhtml (100%) rename {tests => dev}/tables/table-borders.xhtml (100%) rename {tests => dev}/tables/table.xhtml (100%) create mode 100644 meta/plugins/__init__.py create mode 100644 meta/plugins/reftest.py create mode 100644 tests/css/.ref/cascade.xhtml.ref create mode 100644 tests/css/cascade.xhtml diff --git a/.gitignore b/.gitignore index ee3d7ca..b1564eb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ compile_commands.json _local/ *._local *.trace -*.iml \ No newline at end of file +*.iml +.cache diff --git a/tests/borders/borders-test.xhtml b/dev/borders/borders-test.xhtml similarity index 100% rename from tests/borders/borders-test.xhtml rename to dev/borders/borders-test.xhtml diff --git a/tests/borders/borders.xhtml b/dev/borders/borders.xhtml similarity index 100% rename from tests/borders/borders.xhtml rename to dev/borders/borders.xhtml diff --git a/tests/flex/disclone.xhtml b/dev/flex/disclone.xhtml similarity index 100% rename from tests/flex/disclone.xhtml rename to dev/flex/disclone.xhtml diff --git a/tests/inline/history.html b/dev/inline/history.html similarity index 100% rename from tests/inline/history.html rename to dev/inline/history.html diff --git a/tests/inline/the-project.html b/dev/inline/the-project.html similarity index 100% rename from tests/inline/the-project.html rename to dev/inline/the-project.html diff --git a/tests/media-queries/red-or-blue.xhtml b/dev/media-queries/red-or-blue.xhtml similarity index 100% rename from tests/media-queries/red-or-blue.xhtml rename to dev/media-queries/red-or-blue.xhtml diff --git a/tests/normal-flow/normal-flow.xhtml b/dev/normal-flow/normal-flow.xhtml similarity index 100% rename from tests/normal-flow/normal-flow.xhtml rename to dev/normal-flow/normal-flow.xhtml diff --git a/tests/normal-flow/red-square.xhtml b/dev/normal-flow/red-square.xhtml similarity index 100% rename from tests/normal-flow/red-square.xhtml rename to dev/normal-flow/red-square.xhtml diff --git a/tests/tables/ledger.css b/dev/tables/ledger.css similarity index 100% rename from tests/tables/ledger.css rename to dev/tables/ledger.css diff --git a/tests/tables/ledger.xhtml b/dev/tables/ledger.xhtml similarity index 100% rename from tests/tables/ledger.xhtml rename to dev/tables/ledger.xhtml diff --git a/tests/tables/mini-ledger.xhtml b/dev/tables/mini-ledger.xhtml similarity index 100% rename from tests/tables/mini-ledger.xhtml rename to dev/tables/mini-ledger.xhtml diff --git a/tests/tables/table-borders.xhtml b/dev/tables/table-borders.xhtml similarity index 100% rename from tests/tables/table-borders.xhtml rename to dev/tables/table-borders.xhtml diff --git a/tests/tables/table.xhtml b/dev/tables/table.xhtml similarity index 100% rename from tests/tables/table.xhtml rename to dev/tables/table.xhtml diff --git a/meta/plugins/__init__.py b/meta/plugins/__init__.py new file mode 100644 index 0000000..c8dc9b5 --- /dev/null +++ b/meta/plugins/__init__.py @@ -0,0 +1,5 @@ +from cutekit import ensure + +ensure((0, 7, 6)) + +from . import reftest, tools # noqa E402, F401: Needed for side effect diff --git a/meta/plugins/reftest.py b/meta/plugins/reftest.py new file mode 100644 index 0000000..f0509ec --- /dev/null +++ b/meta/plugins/reftest.py @@ -0,0 +1,40 @@ +from cutekit import shell, vt100, cli, builder, model +from pathlib import Path +import dataclasses as dt +from dataclasses_json import DataClassJsonMixin +import tempfile + + +def buildPaperMuncher(args: model.TargetArgs) -> builder.ProductScope: + scope = builder.TargetScope.use(args) + component = scope.registry.lookup("vaev-tools", model.Component) + if component is None: + raise RuntimeError("paper-muncher not found") + return builder.build(scope, component)[0] + + +@cli.command(None, "reftests", "Manage the reftests") +def _(args: model.TargetArgs): + paperMuncher = buildPaperMuncher(args) + + for file in shell.find("tests", ["*.html", "*.xhtml"]): + print(f"Running reftest {file}...") + path = Path(file) + + refPath = path.parent / ".ref" / (path.name + ".ref") + output = paperMuncher.popen("html2pdf", "-sdlpo", "/dev/null", file) + + if not refPath.exists(): + vt100.warning(f"{refPath} not found, creating reference") + refPath.parent.mkdir(parents=True, exist_ok=True) + with refPath.open("x") as ref: + ref.write(output) + continue + + with refPath.open() as ref: + refContent = ref.read() + + if refContent == output: + print(f"{vt100.GREEN}Passed{vt100.RESET}") + else: + print(f"{vt100.RED}Failed{vt100.RESET}") diff --git a/meta/plugins/requirements.txt b/meta/plugins/requirements.txt index d234be3..f25cb7e 100644 --- a/meta/plugins/requirements.txt +++ b/meta/plugins/requirements.txt @@ -1 +1 @@ -git+https://github.com/cute-engineering/cutekit.git@0.7.5 +git+https://github.com/cute-engineering/cutekit.git@0.7.6 diff --git a/meta/targets/host-any.json b/meta/targets/host-any.json index bf9589e..dad64b2 100644 --- a/meta/targets/host-any.json +++ b/meta/targets/host-any.json @@ -10,7 +10,7 @@ "bits": "unknown", "freestanding": false, "host": true, - "version": "{jexpr.include('./meta/scripts/version.json')}", + "version": "0.1.0", "odoo": true, "karm-sys-encoding": "utf8", "karm-sys-line-ending": "lf", @@ -19,7 +19,8 @@ "karm-ui-backend": "sdl" }, "routing": { - "stdc-math": "ce-libm-host" + "stdc-math": "ce-libm-host", + "__main__": "vaev-tools" }, "tools": { "cc": { diff --git a/src/vendors/libs/karm-io/pack.h b/src/vendors/libs/karm-io/pack.h index 0fa7308..3ce1569 100644 --- a/src/vendors/libs/karm-io/pack.h +++ b/src/vendors/libs/karm-io/pack.h @@ -169,8 +169,7 @@ struct Packer { Res<> res = Ok(); ([&] { res ? res = Io::pack(e, fields) : res; - }(), - ...); + }(), ...); return res; }, val diff --git a/tests/css/.ref/cascade.xhtml.ref b/tests/css/.ref/cascade.xhtml.ref new file mode 100644 index 0000000..b361559 --- /dev/null +++ b/tests/css/.ref/cascade.xhtml.ref @@ -0,0 +1,132 @@ +--- START OF DOM --- +(DOCUMENT + (DOCUMENT_TYPE name="html" publicId="" systemId="") + (ELEMENT tagName=html + (ATTRIBUTE localName=HTML:lang value="en") + (TEXT data="\n\n") + (ELEMENT tagName=body + (TEXT data="\n ") + (ELEMENT tagName=div) + (TEXT data="\n") + ) + (TEXT data="\n\n") + (ELEMENT tagName=style + (TEXT data="\n div {\n width: 100px;\n height: 100px;\n background-color: red;\n }\n\n div {\n background-color: green;\n }\n\n div {\n background-color: blue;\n }\n") + ) + (TEXT data="\n\n") + ) +) + +--- END OF DOM --- + +--- START OF STYLE --- +(style-book [(style-sheet text/css . + rules: [ + (style-rule + selector: html + props: [ + (display (display box: CONTENTS)) + ] + ) + (style-rule + selector: (OR [head, style]) + props: [ + (display (display box: NONE)) + ] + ) + (style-rule + selector: table + props: [ + (display (display inside: TABLE, outside: BLOCK, item: NO)) + ] + ) + (style-rule + selector: caption + props: [ + (display (display internal: TABLE_CAPTION)) + ] + ) + (style-rule + selector: colgroup + props: [ + (display (display internal: TABLE_COLUMN_GROUP)) + ] + ) + (style-rule + selector: col + props: [ + (display (display internal: TABLE_COLUMN)) + ] + ) + (style-rule + selector: thead + props: [ + (display (display internal: TABLE_HEADER_GROUP)) + ] + ) + (style-rule + selector: tbody + props: [ + (display (display internal: TABLE_ROW_GROUP)) + ] + ) + (style-rule + selector: tfoot + props: [ + (display (display internal: TABLE_FOOTER_GROUP)) + ] + ) + (style-rule + selector: tr + props: [ + (display (display internal: TABLE_ROW)) + ] + ) + (style-rule + selector: (OR [td, th]) + props: [ + (display (display internal: TABLE_CELL)) + ] + ) + ] +), (style-sheet text/css . + rules: [ + (style-rule + selector: div + props: [ + (width 100PX) + (height 100PX) + (background-color [#00000000, #ff0000ff]) + ] + ) + (style-rule + selector: div + props: [ + (background-color [#00000000, #008000ff]) + ] + ) + (style-rule + selector: div + props: [ + (background-color [#00000000, #0000ffff]) + ] + ) + ] +)]) +--- END OF STYLE --- + +--- START OF LAYOUT --- +(flow (display inside: FLOW, outside: INLINE, item: NO) (rect 0 0 210 100) + (flow (display inside: FLOW, outside: INLINE, item: NO) (rect 0 0 210 100) + (frag (display inside: FLOW, outside: INLINE, item: NO) (rect 0 0 100 100)) + ) +) +--- END OF LAYOUT --- + +--- START OF PAINT --- +(stack + (box (rect 0 0 210 100) (radii 0) [(color #00000000)]) + (box (rect 0 0 210 100) (radii 0) [(color #00000000)]) + (box (rect 0 0 100 100) (radii 0) [(color #00000000), (color #0000ffff)]) +) +--- END OF PAINT --- \ No newline at end of file diff --git a/tests/css/cascade.xhtml b/tests/css/cascade.xhtml new file mode 100644 index 0000000..4fe7133 --- /dev/null +++ b/tests/css/cascade.xhtml @@ -0,0 +1,24 @@ + + + + +
+ + + + +