Skip to content

Commit

Permalink
tools: Initial reftests implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Sep 18, 2024
1 parent 8716f32 commit 98125f3
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ compile_commands.json
_local/
*._local
*.trace
*.iml
*.iml
.cache
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions meta/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cutekit import ensure

ensure((0, 7, 6))

from . import reftest, tools # noqa E402, F401: Needed for side effect
40 changes: 40 additions & 0 deletions meta/plugins/reftest.py
Original file line number Diff line number Diff line change
@@ -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}")
2 changes: 1 addition & 1 deletion meta/plugins/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/cute-engineering/[email protected].5
git+https://github.com/cute-engineering/[email protected].6
5 changes: 3 additions & 2 deletions meta/targets/host-any.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,7 +19,8 @@
"karm-ui-backend": "sdl"
},
"routing": {
"stdc-math": "ce-libm-host"
"stdc-math": "ce-libm-host",
"__main__": "vaev-tools"
},
"tools": {
"cc": {
Expand Down
3 changes: 1 addition & 2 deletions src/vendors/libs/karm-io/pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ struct Packer<T> {
Res<> res = Ok();
([&] {
res ? res = Io::pack(e, fields) : res;
}(),
...);
}(), ...);
return res;
},
val
Expand Down
132 changes: 132 additions & 0 deletions tests/css/.ref/cascade.xhtml.ref
Original file line number Diff line number Diff line change
@@ -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 ---
24 changes: 24 additions & 0 deletions tests/css/cascade.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">

<body>
<div />
</body>

<style>
div {
width: 100px;
height: 100px;
background-color: red;
}

div {
background-color: green;
}

div {
background-color: blue;
}
</style>

</html>

0 comments on commit 98125f3

Please sign in to comment.