Skip to content

Conversation

@hugopl
Copy link
Collaborator

@hugopl hugopl commented Mar 7, 2025

Codegen is not tested at all, so before think about fix it is better to add tests for it.

The plan is:

  • Let golden test run against codegen visitor.
  • Compare codegen output with expected golden test output.
  • Fix the code gen.

I had some time today and made the tests run against the codegen, still in a "it worked" state, very draft, but I'm pushing it here because if someone with time is interested in fix this there's something to start on.

All codegen tests are tagged with codegen, currently if you run: crystal spec --tag codegen --fail-fast you will reproduce issue #87

$ crystal spec --tag codegen --fail-fast
In spec/integration/4wtigu49-liquid-codegen-test.cr:4:3

 4 | {{ run "../../src/process", "/home/hugo/src/pet/liquid.cr/spec/integration/x6qfc7po-test.liquid", "io", "context" }}
     ^
Error: expanding macro


In src/process.cr:7:5

 7 | tpl.to_code io, STDOUT, context
         ^------
Error: instantiating 'Liquid::Template#to_code(String, IO::FileDescriptor, (String | Nil))'


In src/liquid/template.cr:60:12

 60 | root.accept visitor
           ^-----
Error: instantiating 'Liquid::Block::Root#accept(Liquid::CodeGenVisitor)'


In src/liquid/blocks/block.cr:12:15

 12 | visitor.visit self
              ^----
Error: instantiating 'Liquid::CodeGenVisitor#visit(Liquid::Block::Root)'


In src/liquid/codegen_visitor.cr:49:28

 49 | node.children.each &.accept self
                           ^-----
Error: instantiating 'Liquid::Block::Node+#accept(Liquid::CodeGenVisitor)'


In src/liquid/blocks/block.cr:12:15

 12 | visitor.visit self
              ^----
Error: instantiating 'Liquid::CodeGenVisitor#visit(Liquid::Block::Node+)'


In src/liquid/codegen_visitor.cr:58:76

 58 | Liquid::Block::ExpressionNode.new("#{escape node.value.var}")))
                                                             ^--
Error: undefined method 'var' for Liquid::Expression
F

Failures:

  1) Golden Liquid Tests liquid.golden.abs_filter negative float (codegen)
     Failure/Error: $?.exit_code.should eq(0)

       Expected: 0
            got: 1

     # spec/integration/integration_spec.cr:43

Aborted!
Finished in 626.58 milliseconds
1 examples, 1 failures, 0 errors, 0 pending

Failed examples:

crystal spec spec/integration/integration_spec.cr:1 # Golden Liquid Tests liquid.golden.abs_filter negative float (codegen)

@hugopl hugopl marked this pull request as draft March 7, 2025 23:02
@hugopl hugopl added the P-high label Mar 7, 2025
@hugopl hugopl changed the title Draft: Fix codegen Fix codegen Mar 12, 2025
@hugopl hugopl marked this pull request as ready for review March 12, 2025 22:59
@hugopl hugopl requested a review from crimson-knight March 13, 2025 13:08
@straight-shoota

This comment was marked as duplicate.

@straight-shoota
Copy link

straight-shoota commented Mar 17, 2025

I'd suggest moving the formatter test to a separate job. It's unrelated to the specs. And it doesn't need to run in matrix, the behaviour will be identical regardless of which OS it runs on. This might be out of scope of this PR, of course.

@hugopl
Copy link
Collaborator Author

hugopl commented Mar 18, 2025

I added ameba github action in another PR, so it must do the format check.

Now we just need someone to review, approve and merge both PR's

@hugopl hugopl requested review from drujensen and elorest March 18, 2025 17:46
@crimson-knight crimson-knight merged commit e809da0 into amberframework:master Mar 21, 2025
@hugopl hugopl deleted the fix-codegen branch May 20, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants