File: kernel_require_test.rb

package info (click to toggle)
ruby-derailed-benchmarks 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 760 kB
  • sloc: ruby: 1,317; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download
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
29
30
31
32
33
# frozen_string_literal: true

require 'test_helper'

class KernelRequireTest < ActiveSupport::TestCase

  setup do
    require 'derailed_benchmarks/core_ext/kernel_require'
    GC.disable
  end

  teardown do
    GC.enable
  end

  def assert_node_in_parent(file_name, parent)
    file = fixtures_dir(File.join("require", file_name))
    node = parent[file]
    assert node,                    "Expected:\n#{parent.children}\nto include:\n#{file.inspect}"
    assert node.cost < parent.cost, "Expected:\n#{node.inspect}\nto cost less than:\n#{parent.inspect}" unless parent == TOP_REQUIRE
    node
  end

  test "core extension profiles useage" do
    require fixtures_dir("require/parent_one.rb")
    parent    = assert_node_in_parent("parent_one.rb", TOP_REQUIRE)
    assert_node_in_parent("child_one.rb", parent)
    child_two = assert_node_in_parent("child_two.rb", parent)
    assert_node_in_parent("relative_child", parent)
    assert_node_in_parent("relative_child_two", parent)
    assert_node_in_parent("raise_child.rb", child_two)
  end
end