forked from mirrors/jj
cli: add test to ensure the default config has no symbol aliases
In #4432 I submitted a patch to ship a symbol alias in the default configuration. However, Yuya quickly pointed out that this isn't acceptable because symbols override all branch and tag names, meaning that the name `at` would have at best been taken away from users, and at worst been very confusing for them down the road had they ever tried to use it. I should have thought of this myself (I encountered it long ago when first using Jujutsu, actually) but didn't. Such is life. But this didn't cause any tests to fail, as it was not immediately clear this would impede anything or cause downstream behavioral changes; the problems it adds are actually latent and it's very possible someone will want to make the same mistake in the future. And Yuya might not be able to stop them (me) in time; requiring him to go out of his way and then handle the fallout. I'm not a fan of this. Instead, let's patch this latent hole for good, or until we decide otherwise, by applying the Beyonce Rule: "if you liked that behavior, then you shoulda put a test on it." Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
parent
831404628f
commit
799511c20d
1 changed files with 32 additions and 0 deletions
|
@ -1270,6 +1270,38 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ban_default_symbol_aliases() -> anyhow::Result<()> {
|
||||
// NOTE(aseipp): symbol aliases override all branches and tags, so we
|
||||
// must ban them from being introduced in the default `revset-aliases`
|
||||
//
|
||||
// relevant issue: https://github.com/martinvonz/jj/pull/4432
|
||||
for (alias, _) in default_config().get_table("revset-aliases")?.iter() {
|
||||
// an alias could be something like:
|
||||
//
|
||||
// 'foo()' = ...
|
||||
// 'foo(x,y)' = ...
|
||||
//
|
||||
// but can never be something like:
|
||||
//
|
||||
// 'foo)' = ...
|
||||
// '(foo)' = ...
|
||||
//
|
||||
// and so testing for the presence of a closing parenthesis is
|
||||
// sufficient to ensure we're not introducing a symbol.
|
||||
if !alias.ends_with(")") {
|
||||
anyhow::bail!(
|
||||
"symbol alias `{}` is not allowed in the default configuration; alias must be \
|
||||
a nullary function i.e. '{}()'",
|
||||
alias,
|
||||
alias
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_config_fs(files: &Vec<&'static str>) -> anyhow::Result<tempfile::TempDir> {
|
||||
let tmp = testutils::new_temp_dir();
|
||||
for file in files {
|
||||
|
|
Loading…
Reference in a new issue