#!/usr/bin/ruby

var f = { (5, 6) }.ffork
var g = { 6 }.ffork

var a1 = [f.wait]
var a2 = [g.wait]

assert_eq(a1, [5, 6])
assert_eq(a2, [6])

#
## Loading Perl modules inside a file-fork
#

do {
    var t = { 'JSON'.require }.ffork.wait
    assert_eq(t.new.encode(Hash(a => 1)), %({"a":1}))
}

do {
    var t = { 'JSON::PP'.frequire }.ffork.wait
    assert_eq(t.encode_json(Hash(a => 1)), %({"a":1}))
}

do {
    var t =  {
        var lwp = try { "LWP::UserAgent".require.new(
            timeout => 30,
            show_progress => 1,
        ) } \\ Sys.kill('KILL', $$)
        lwp.default_header("Referer" => "foo")
        lwp
    }.ffork

    var r = t.wait \\ die "LWP::UserAgent cannot be loaded"
    assert_eq(r.default_header("Referer"), "foo")
    r.default_header("Referer" => "bar")
    assert_eq(r.default_header("Referer"), "bar")
}

say "** Test passed!"
