aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-02-09 17:49:42 -0500
committerRyan Ofsky <ryan@ofsky.org>2022-03-02 06:09:27 -0500
commit687e655ae2970f2f13aca0267c7de86dc69be763 (patch)
treeeb8b47e8253d573200690f8a0951a29e083c0192 /src/test
parent08bcfa27675da5c65e4c9eab7e7764eab0599298 (diff)
downloadbitcoin-687e655ae2970f2f13aca0267c7de86dc69be763.tar.xz
util: Add GetPathArg default path argument
Let GetPathArg method be used more places for path arguments that have default values, like "-settings" and BITCOIN_SETTINGS_FILENAME in the next commit. Also: - Fix negated argument handling. Return path{} not path{"0"} when path argument is negated. - Add new tests for default and negated cases - Move GetPathArg() method declaration next to GetArg() declarations. The two methods are close substitutes for each other, so this should help keep them consistent and make them more discoverable.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/getarg_tests.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp
index ef9d72dcde..76a65ec528 100644
--- a/src/test/getarg_tests.cpp
+++ b/src/test/getarg_tests.cpp
@@ -245,6 +245,24 @@ BOOST_AUTO_TEST_CASE(patharg)
ResetArgs(local_args, "-dir=user/.bitcoin/.//");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
+
+ // Check negated and default argument handling. Specifying an empty argument
+ // is the same as not specifying the argument. This is convenient for
+ // scripting so later command line arguments can override earlier command
+ // line arguments or bitcoin.conf values. Currently the -dir= case cannot be
+ // distinguished from -dir case with no assignment, but #16545 would add the
+ // ability to distinguish these in the future (and treat the no-assign case
+ // like an imperative command or an error).
+ ResetArgs(local_args, "");
+ BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
+ ResetArgs(local_args, "-dir=override");
+ BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"override"});
+ ResetArgs(local_args, "-dir=");
+ BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
+ ResetArgs(local_args, "-dir");
+ BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
+ ResetArgs(local_args, "-nodir");
+ BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{""});
}
BOOST_AUTO_TEST_CASE(doubledash)