Skip to content

Commit

Permalink
Strip any leading directory path from the argv[0] program name in `pu…
Browse files Browse the repository at this point in the history
…re2-main-args` test to have consistent results on CI agent as well as local runs (hsutter#947)
  • Loading branch information
bluetarpmedia authored Jan 18, 2024
1 parent 087af3c commit c14d78b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
11 changes: 9 additions & 2 deletions regression-tests/pure2-main-args.cpp2
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
main: (args) =
main: (args) = {
exe: std::string = args.argv[0];
pos:= exe.find_last_of("/\\");
if pos != std::string::npos {
pos++;
exe = exe.substr(pos, exe.size() - pos);
}
std::cout
<< "args.argc is (args.argc)$\n"
<< "args.argv[0] is (args.argv[0])$\n"
<< "args.argv[0] is (exe)$\n"
;
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.argv[0] is test.exe
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.argv[0] is test.exe
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.argv[0] is test.exe
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.argv[0] is test.exe
12 changes: 10 additions & 2 deletions regression-tests/test-results/pure2-main-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ auto main(int const argc_, char** argv_) -> int;
//=== Cpp2 function definitions =================================================

#line 1 "pure2-main-args.cpp2"
auto main(int const argc_, char** argv_) -> int {
auto main(int const argc_, char** argv_) -> int{
auto const args = cpp2::make_args(argc_, argv_);
#line 2 "pure2-main-args.cpp2"
std::string exe {CPP2_ASSERT_IN_BOUNDS_LITERAL(args.argv, 0)};
auto pos {CPP2_UFCS(find_last_of)(exe, "/\\")};
if (pos != std::string::npos) {
++pos;
exe = CPP2_UFCS(substr)(exe, pos, CPP2_UFCS(size)(exe) - std::move(pos));
}
std::cout
<< ("args.argc is " + cpp2::to_string(args.argc) + "\n")
<< ("args.argv[0] is " + cpp2::to_string(CPP2_ASSERT_IN_BOUNDS_LITERAL(args.argv, 0)) + "\n"); }
<< ("args.argv[0] is " + cpp2::to_string(std::move(exe)) + "\n");

}

0 comments on commit c14d78b

Please sign in to comment.