Repository: JuliaLang/julia
File: test/cmdlineargs.jl (Julia)

Code before:
        # get the homedir, as reported by uv_os_get_passwd, as used by jl_format_filename
        try
            homedir()
        catch ex
            (ex isa Base.IOError && ex.code == Base.UV_ENOENT) || rethrow(ex)
            ""
        end
    end
    @test startswith(fn, "a$hd ")
    @test endswith(fn, " z")
    @test !occursin('%', fn)
    @test occursin(" $(getpid()) ", fn)
    @test occursin(" $(Libc.gethostname()) ", fn)
    @test format_filename("%a%%b") == "a%b"
end

if Sys.isunix()
    @testset "SIGQUIT prints task backtraces" begin
        script = """
            mutable struct RLimit
                cur::Int64
                max::Int64
            end
            const RLIMIT_CORE = 4 # from /usr/include/sys/resource.h
            ccall(:setrlimit, Cint, (Cint, Ref{RLimit}), RLIMIT_CORE, Ref(RLimit(0, 0)))
            sleep(20.0) # allow Julia to start
        """
        exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
        errp = Base.PipeEndpoint()
        # disable coredumps for this process
        p = run(`$exename -e $script`, devnull, devnull, errp, wait=false)
        sleep(5.0) # allow Julia to start
        Base.kill(p, Base.SIGQUIT)
        wait(p)
        err_s = readchomp(errp)
        @test Base.process_signaled(p) && p.termsignal == Base.SIGQUIT
        @test occursin("==== Thread ", err_s)
        @test occursin("==== Done", err_s)
    end
end

@testset "julia_cmd" begin
    julia_basic = Base.julia_cmd()
    function get_julia_cmd(arg)
        io = Base.BufferStream()
        cmd = `$julia_basic $arg -e 'print(repr(Base.julia_cmd()))'`
        try
            run(pipeline(cmd, stdout=io, stderr=io))
        catch
            closewrite(io)
            @error "cmd failed" cmd read(io, String)

Review comment (suggestion):
```suggestion
            write(stdout, "r")
            eof(stdout)
```

Code after:
        # get the homedir, as reported by uv_os_get_passwd, as used by jl_format_filename
        try
            homedir()
        catch ex
            (ex isa Base.IOError && ex.code == Base.UV_ENOENT) || rethrow(ex)
            ""
        end
    end
    @test startswith(fn, "a$hd ")
    @test endswith(fn, " z")
    @test !occursin('%', fn)
    @test occursin(" $(getpid()) ", fn)
    @test occursin(" $(Libc.gethostname()) ", fn)
    @test format_filename("%a%%b") == "a%b"
end

if Sys.isunix()
    @testset "SIGQUIT prints task backtraces" begin
        script = """
            mutable struct RLimit
                cur::Int64
                max::Int64
            end
            const RLIMIT_CORE = 4 # from /usr/include/sys/resource.h
            ccall(:setrlimit, Cint, (Cint, Ref{RLimit}), RLIMIT_CORE, Ref(RLimit(0, 0)))
            write(stdout, "r")
            wait()
        """
        exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
        errp = PipeBuffer()
        # disable coredumps for this process
        p = open(pipeline(`$exename -e $script`, stderr=errp), "r")
        @test read(p, UInt8) == UInt8('r')
        Base.kill(p, Base.SIGQUIT)
        wait(p)
        err_s = readchomp(errp)
        @test Base.process_signaled(p) && p.termsignal == Base.SIGQUIT
        @test occursin("==== Thread ", err_s)
        @test occursin("==== Done", err_s)
    end
end

@testset "julia_cmd" begin
    julia_basic = Base.julia_cmd()
    function get_julia_cmd(arg)
        io = Base.BufferStream()
        cmd = `$julia_basic $arg -e 'print(repr(Base.julia_cmd()))'`
        try
            run(pipeline(cmd, stdout=io, stderr=io))
        catch
            closewrite(io)