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

Code before:

    # --help
    let header = "\n    julia [switches] -- [programfile] [args...]"
        @test startswith(read(`$exename -h`, String), header)
        @test startswith(read(`$exename --help`, String), header)
    end

    # ~ expansion in --project and JULIA_PROJECT
    if !Sys.iswindows()
        let expanded = abspath(expanduser("~/foo/Project.toml"))
            @test expanded == readchomp(`$exename --project='~/foo' -e 'println(Base.active_project())'`)
            @test expanded == readchomp(setenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "~/foo", "HOME" => homedir()))
        end
    end

    # handling of @projectname in --project and JULIA_PROJECT
    let expanded = abspath(Base.load_path_expand("@foo"))
        @test expanded == readchomp(`$exename --project='@foo' -e 'println(Base.active_project())'`)
        @test expanded == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@foo", "HOME" => homedir()))
    end

    # --project=@script handling
    let expanded = abspath(joinpath(@__DIR__, "project", "ScriptProject"))
        script = joinpath(expanded, "bin", "script.jl")
        # Check running julia with --project=@script both within and outside the script directory
        @testset "--@script from $name" for (name, dir) in [("project", expanded, ("outside", pwd()))]
            @test joinpath(expanded, "Project.toml") == readchomp(Cmd(`$exename --project=@script $script`; dir))
            @test joinpath(expanded, "SubProject", "Project.toml") == readchomp(Cmd(`$exename --project=@script/../SubProject $script`; dir))
        end
    end

    # handling of `@temp` in --project and JULIA_PROJECT
    @test tempdir() == readchomp(`$exename --project=@temp -e 'println(Base.active_project())'`)[1:lastindex(tempdir())]
    @test tempdir() == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@temp", "HOME" => homedir()))[1:lastindex(tempdir())]

    # --quiet, --banner
    let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
        @test read(`$exename                   -e $p`, String) == "(0, -1)"
        @test read(`$exename -q                -e $p`, String) == "(1, 0)"
        @test read(`$exename --quiet           -e $p`, String) == "(1, 0)"
        @test read(`$exename --banner=no       -e $p`, String) == "(0, 0)"
        @test read(`$exename --banner=yes      -e $p`, String) == "(0, 1)"
        @test read(`$exename --banner=short    -e $p`, String) == "(0, 2)"
        @test read(`$exename -q --banner=no    -e $p`, String) == "(1, 0)"
        @test read(`$exename -q --banner=yes   -e $p`, String) == "(1, 1)"
        @test read(`$exename -q --banner=short -e $p`, String) == "(1, 2)"
        @test read(`$exename --banner=no  -q   -e $p`, String) == "(1, 0)"
        @test read(`$exename --banner=yes -q   -e $p`, String) == "(1, 1)"
        @test read(`$exename --banner=short -q -e $p`, String) == "(1, 2)"
    end


Review comment (suggestion):
It looks like this `for` loop has a misplaced closing parenthesis:
```julia
[("project", expanded, ("outside", pwd()))]
                                         ^
```
I'm guessing it should be
```julia
[("project", expanded), ("outside", pwd())]
                     ^
```
Otherwise this loop has only one iteration and ignores `"outside"` and `pwd()`.

Code after:

    # --help
    let header = "\n    julia [switches] -- [programfile] [args...]"
        @test startswith(read(`$exename -h`, String), header)
        @test startswith(read(`$exename --help`, String), header)
    end

    # ~ expansion in --project and JULIA_PROJECT
    if !Sys.iswindows()
        let expanded = abspath(expanduser("~/foo/Project.toml"))
            @test expanded == readchomp(`$exename --project='~/foo' -e 'println(Base.active_project())'`)
            @test expanded == readchomp(setenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "~/foo", "HOME" => homedir()))
        end
    end

    # handling of @projectname in --project and JULIA_PROJECT
    let expanded = abspath(Base.load_path_expand("@foo"))
        @test expanded == readchomp(`$exename --project='@foo' -e 'println(Base.active_project())'`)
        @test expanded == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@foo", "HOME" => homedir()))
    end

    # --project=@script handling
    let expanded = abspath(joinpath(@__DIR__, "project", "ScriptProject"))
        script = joinpath(expanded, "bin", "script.jl")
        # Check running julia with --project=@script both within and outside the script directory
        @testset "--@script from $name" for (name, dir) in [("project", expanded), ("outside", pwd())]
            @test joinpath(expanded, "Project.toml") == readchomp(Cmd(`$exename --project=@script $script`; dir))
            @test joinpath(expanded, "SubProject", "Project.toml") == readchomp(Cmd(`$exename --project=@script/../SubProject $script`; dir))
        end
    end

    # handling of `@temp` in --project and JULIA_PROJECT
    @test tempdir() == readchomp(`$exename --project=@temp -e 'println(Base.active_project())'`)[1:lastindex(tempdir())]
    @test tempdir() == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@temp", "HOME" => homedir()))[1:lastindex(tempdir())]

    # --quiet, --banner
    let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
        @test read(`$exename                   -e $p`, String) == "(0, -1)"
        @test read(`$exename -q                -e $p`, String) == "(1, 0)"
        @test read(`$exename --quiet           -e $p`, String) == "(1, 0)"
        @test read(`$exename --banner=no       -e $p`, String) == "(0, 0)"
        @test read(`$exename --banner=yes      -e $p`, String) == "(0, 1)"
        @test read(`$exename --banner=short    -e $p`, String) == "(0, 2)"
        @test read(`$exename -q --banner=no    -e $p`, String) == "(1, 0)"
        @test read(`$exename -q --banner=yes   -e $p`, String) == "(1, 1)"
        @test read(`$exename -q --banner=short -e $p`, String) == "(1, 2)"
        @test read(`$exename --banner=no  -q   -e $p`, String) == "(1, 0)"
        @test read(`$exename --banner=yes -q   -e $p`, String) == "(1, 1)"
        @test read(`$exename --banner=short -q -e $p`, String) == "(1, 2)"
    end