From e9b24327d00dec33f83c6d207d4c616af866f98c Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 19 Aug 2017 20:09:44 -0700 Subject: [PATCH] Make argparse error message deterministic Recent changes to switch to unordered sets/maps can cause the order in which items are returned to be non-deterministic. This change ensures that the argparse "Mutually exclusive flags" error message to be deterministic with respect to the order of the interpolated values. --- src/builtin_argparse.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index bfaf4ce29..2749a8594 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -118,6 +118,13 @@ static int check_for_mutually_exclusive_flags(argparse_cmd_opts_t &opts, io_stre if (xopt_spec->short_flag_valid) flag2 += L"/"; flag2 += xopt_spec->long_flag; } + // We want the flag order to be deterministic. Primarily to make unit + // testing easier. + if (flag1 > flag2) { + wcstring tmp(flag1); + flag2 = flag1; + flag1 = tmp; + } streams.err.append_format( _(L"%ls: Mutually exclusive flags '%ls' and `%ls` seen\n"), opts.name.c_str(), flag1.c_str(), flag2.c_str());