File: gc_stress_test.rb

package info (click to toggle)
ruby-liquid-c 4.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 544 kB
  • sloc: ansic: 3,866; ruby: 1,135; makefile: 7
file content (28 lines) | stat: -rw-r--r-- 562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# encoding: utf-8
# frozen_string_literal: true

require "test_helper"

# Help catch bugs from objects not being marked at all
# GC opportunities.
class GCStressTest < Minitest::Test
  def test_compile_and_render
    source = "{% assign x = 1 %}{% if x -%} x: {{ x | plus: 2 }}{% endif %}"
    result = gc_stress do
      Liquid::Template.parse(source).render!
    end
    assert_equal("x: 3", result)
  end

  private

  def gc_stress
    old_value = GC.stress
    GC.stress = true
    begin
      yield
    ensure
      GC.stress = old_value
    end
  end
end