From bbd56d53ecc0673a5e3b3a5f1e8faaa27c51c533 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sun, 12 Nov 2023 15:16:15 -0500 Subject: [PATCH 1/3] tryfix abspath c func with "" on windows --- src/init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/init.c b/src/init.c index fef3e73bd2d06..e652af8317879 100644 --- a/src/init.c +++ b/src/init.c @@ -575,6 +575,14 @@ static char *abspath(const char *in, int nprefix) } } #else + // GetFullPathName intentionally errors if given an empty string so manually insert `.` to invoke cwd + char *in2 = (char*)malloc_s(JL_PATH_MAX); + if (strlen(in) - nprefix == 0) { + memcpy(in2, in, nprefix); + in2[nprefix+1] = '.'; + in2[nprefix+2] = '\0'; + in = in2; + } DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL); if (n <= 0) { jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed"); @@ -585,6 +593,7 @@ static char *abspath(const char *in, int nprefix) jl_error("fatal error: jl_options.image_file path too long or GetFullPathName failed"); } memcpy(out, in, nprefix); + free(in2); #endif return out; } From dcb2ed0b09f206db391765052ff36343f26b5615 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sun, 12 Nov 2023 19:25:35 -0500 Subject: [PATCH 2/3] use abspath for tracking path --- src/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index e652af8317879..5af9a3612e294 100644 --- a/src/init.c +++ b/src/init.c @@ -579,8 +579,8 @@ static char *abspath(const char *in, int nprefix) char *in2 = (char*)malloc_s(JL_PATH_MAX); if (strlen(in) - nprefix == 0) { memcpy(in2, in, nprefix); - in2[nprefix+1] = '.'; - in2[nprefix+2] = '\0'; + in2[nprefix] = '.'; + in2[nprefix+1] = '\0'; in = in2; } DWORD n = GetFullPathName(in + nprefix, 0, NULL, NULL); @@ -689,7 +689,7 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel) if (jl_options.output_code_coverage) jl_options.output_code_coverage = absformat(jl_options.output_code_coverage); if (jl_options.tracked_path) - jl_options.tracked_path = absformat(jl_options.tracked_path); + jl_options.tracked_path = abspath(jl_options.tracked_path, 0); const char **cmdp = jl_options.cmds; if (cmdp) { From ba3c1f0be0a8db017d514567191d4229a07279e3 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 13 Nov 2023 19:40:15 -0500 Subject: [PATCH 3/3] expand tests --- test/cmdlineargs.jl | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index c1681532d26ea..476ee58c02a79 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -473,10 +473,47 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no` @test occursin(expected, got) || (expected, got) @test_broken occursin(expected_good, got) + # Ask for coverage in current directory + tdir = dirname(realpath(inputfile)) + cd(tdir) do + # there may be atrailing separator here so use rstrip + @test readchomp(`$exename -E "(Base.JLOptions().code_coverage, rstrip(unsafe_string(Base.JLOptions().tracked_path), '/'))" -L $inputfile + --code-coverage=$covfile --code-coverage=@`) == "(3, $(repr(tdir)))" + end + @test isfile(covfile) + got = read(covfile, String) + rm(covfile) + @test occursin(expected, got) || (expected, got) + @test_broken occursin(expected_good, got) + + # Ask for coverage in relative directory + tdir = dirname(realpath(inputfile)) + cd(dirname(tdir)) do + @test readchomp(`$exename -E "(Base.JLOptions().code_coverage, unsafe_string(Base.JLOptions().tracked_path))" -L $inputfile + --code-coverage=$covfile --code-coverage=@testhelpers`) == "(3, $(repr(tdir)))" + end + @test isfile(covfile) + got = read(covfile, String) + rm(covfile) + @test occursin(expected, got) || (expected, got) + @test_broken occursin(expected_good, got) + + # Ask for coverage in relative directory with dot-dot notation + tdir = dirname(realpath(inputfile)) + cd(tdir) do + @test readchomp(`$exename -E "(Base.JLOptions().code_coverage, unsafe_string(Base.JLOptions().tracked_path))" -L $inputfile + --code-coverage=$covfile --code-coverage=@../testhelpers`) == "(3, $(repr(tdir)))" + end + @test isfile(covfile) + got = read(covfile, String) + rm(covfile) + @test occursin(expected, got) || (expected, got) + @test_broken occursin(expected_good, got) + # Ask for coverage in a different directory tdir = mktempdir() # a dir that contains no code @test readchomp(`$exename -E "(Base.JLOptions().code_coverage, unsafe_string(Base.JLOptions().tracked_path))" -L $inputfile - --code-coverage=$covfile --code-coverage=@$tdir`) == "(3, $(repr(tdir)))" + --code-coverage=$covfile --code-coverage=@$tdir`) == "(3, $(repr(realpath(tdir))))" @test isfile(covfile) got = read(covfile, String) @test isempty(got)