1
1
mirror of https://github.com/casey/just.git synced 2024-11-22 18:34:06 +03:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Sibi Prabakaran
b44cd99ec5
Merge 6fc9e54577 into 17350a603e 2024-11-19 07:43:07 +05:30
Sibi Prabakaran
6fc9e54577
Fix remaining failing tests 2024-11-18 08:53:55 +05:30
Sibi Prabakaran
3593976837
Use canonicalize to resolve macos failures 2024-11-18 08:50:28 +05:30
Sibi Prabakaran
1676f0b901
Remove duplicate test 2024-11-17 22:41:31 +05:30
Sibi Prabakaran
516fac504c
Add source information as path of the information
Motivation: To add support for module integration in justl which is an
Emacs extension for driving justfiles within Emacs.

This would allow me to easily discover the file locations of different
just modules and allow the ability to individually open justl buffers
for them within the editor.
2024-11-17 22:29:06 +05:30
4 changed files with 1059 additions and 937 deletions

View File

@ -182,6 +182,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
unstable_features.insert(UnstableFeature::ScriptInterpreterSetting); unstable_features.insert(UnstableFeature::ScriptInterpreterSetting);
} }
let source = root.canonicalize().unwrap();
let root = paths.get(root).unwrap(); let root = paths.get(root).unwrap();
Ok(Justfile { Ok(Justfile {
@ -205,7 +206,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
name, name,
recipes, recipes,
settings, settings,
source: root.into(), source,
unexports: self.unexports, unexports: self.unexports,
unstable_features, unstable_features,
warnings: self.warnings, warnings: self.warnings,

View File

@ -23,7 +23,6 @@ pub(crate) struct Justfile<'src> {
pub(crate) name: Option<Name<'src>>, pub(crate) name: Option<Name<'src>>,
pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>, pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>,
pub(crate) settings: Settings<'src>, pub(crate) settings: Settings<'src>,
#[serde(skip)]
pub(crate) source: PathBuf, pub(crate) source: PathBuf,
pub(crate) unexports: HashSet<String>, pub(crate) unexports: HashSet<String>,
#[serde(skip)] #[serde(skip)]

View File

@ -1,22 +1,37 @@
use super::*; use super::*;
fn case(justfile: &str, value: Value) { fn case<F: Fn(&Path) -> Value>(justfile: &str, value: F) {
Test::new() Test::new()
.justfile(justfile) .justfile(justfile)
.args(["--dump", "--dump-format", "json"]) .args(["--dump", "--dump-format", "json"])
.stdout(format!("{}\n", serde_json::to_string(&value).unwrap())) .stdout_with_tempdir(|dir| {
format!(
"{}\n",
serde_json::to_string(&value(&dir.path().canonicalize().unwrap())).unwrap()
)
})
.run(); .run();
} }
#[test] #[test]
fn alias() { fn alias() {
case( let test = Test::new().justfile(
" "
alias f := foo alias f := foo
foo: foo:
", ",
json!({ );
let source = test
.tempdir
.path()
.canonicalize()
.unwrap()
.join("justfile")
.to_str()
.unwrap()
.to_owned();
let json = json!({
"first": "foo", "first": "foo",
"doc": null, "doc": null,
"aliases": { "aliases": {
@ -66,14 +81,18 @@ fn alias() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); });
test
.args(["--dump", "--dump-format", "json"])
.stdout(format!("{}\n", serde_json::to_string(&json).unwrap()))
.run();
} }
#[test] #[test]
fn assignment() { fn assignment() {
case( case("foo := 'bar'", |dir| {
"foo := 'bar'", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": { "assignments": {
@ -110,8 +129,9 @@ fn assignment() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
@ -122,6 +142,8 @@ fn private_assignment() {
[private] [private]
bar := 'bar' bar := 'bar'
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": { "assignments": {
@ -164,7 +186,9 @@ fn private_assignment() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -176,6 +200,8 @@ fn body() {
bar bar
abc{{ 'xyz' }}def abc{{ 'xyz' }}def
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -222,7 +248,9 @@ fn body() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -233,6 +261,8 @@ fn dependencies() {
foo: foo:
bar: foo bar: foo
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -292,7 +322,9 @@ fn dependencies() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -316,6 +348,8 @@ fn dependency_argument() {
replace('a', 'b', 'c') replace('a', 'b', 'c')
) )
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"first": "foo", "first": "foo",
@ -400,7 +434,9 @@ fn dependency_argument() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -414,6 +450,8 @@ fn duplicate_recipes() {
foo: foo:
foo bar: foo bar:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"first": "foo", "first": "foo",
"doc": null, "doc": null,
@ -470,7 +508,9 @@ fn duplicate_recipes() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -482,6 +522,8 @@ fn duplicate_variables() {
x := 'foo' x := 'foo'
x := 'bar' x := 'bar'
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": { "assignments": {
@ -518,14 +560,16 @@ fn duplicate_variables() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
#[test] #[test]
fn doc_comment() { fn doc_comment() {
case( case("# hello\nfoo:", |dir| {
"# hello\nfoo:", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"first": "foo", "first": "foo",
@ -569,14 +613,15 @@ fn doc_comment() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
fn empty_justfile() { fn empty_justfile() {
case( case("", |dir| {
"", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -606,8 +651,9 @@ fn empty_justfile() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
@ -621,6 +667,8 @@ fn parameters() {
e *x: e *x:
f $x: f $x:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"first": "a", "first": "a",
@ -764,7 +812,9 @@ fn parameters() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -776,6 +826,8 @@ fn priors() {
b: a && c b: a && c
c: c:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -855,14 +907,16 @@ fn priors() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
#[test] #[test]
fn private() { fn private() {
case( case("_foo:", |dir| {
"_foo:", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -906,14 +960,15 @@ fn private() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
fn quiet() { fn quiet() {
case( case("@foo:", |dir| {
"@foo:", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -957,8 +1012,9 @@ fn quiet() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
@ -977,6 +1033,8 @@ fn settings() {
foo: foo:
#!bar #!bar
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1023,7 +1081,9 @@ fn settings() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -1034,6 +1094,8 @@ fn shebang() {
foo: foo:
#!bar #!bar
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1077,14 +1139,16 @@ fn shebang() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
#[test] #[test]
fn simple() { fn simple() {
case( case("foo:", |dir| {
"foo:", let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1128,8 +1192,9 @@ fn simple() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
); })
});
} }
#[test] #[test]
@ -1139,6 +1204,8 @@ fn attribute() {
[no-exit-message] [no-exit-message]
foo: foo:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1182,7 +1249,9 @@ fn attribute() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -1199,7 +1268,24 @@ fn module() {
"foo.just": "bar:", "foo.just": "bar:",
}) })
.args(["--dump", "--dump-format", "json"]) .args(["--dump", "--dump-format", "json"])
.stdout(format!( .stdout_with_tempdir(|dir| {
let source = dir
.path()
.canonicalize()
.unwrap()
.join("justfile")
.to_str()
.unwrap()
.to_owned();
let foo_just = dir
.path()
.canonicalize()
.unwrap()
.join("foo.just")
.to_str()
.unwrap()
.to_owned();
format!(
"{}\n", "{}\n",
serde_json::to_string(&json!({ serde_json::to_string(&json!({
"aliases": {}, "aliases": {},
@ -1251,6 +1337,7 @@ fn module() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
"source": foo_just
}, },
}, },
"recipes": {}, "recipes": {},
@ -1275,9 +1362,11 @@ fn module() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
"source": source
})) }))
.unwrap() .unwrap()
)) )
})
.run(); .run();
} }
@ -1294,7 +1383,24 @@ fn module_group() {
"foo.just": "bar:", "foo.just": "bar:",
}) })
.args(["--dump", "--dump-format", "json"]) .args(["--dump", "--dump-format", "json"])
.stdout(format!( .stdout_with_tempdir(|dir| {
let source = dir
.path()
.canonicalize()
.unwrap()
.join("justfile")
.to_str()
.unwrap()
.to_owned();
let foo_just = dir
.path()
.canonicalize()
.unwrap()
.join("foo.just")
.to_str()
.unwrap()
.to_owned();
format!(
"{}\n", "{}\n",
serde_json::to_string(&json!({ serde_json::to_string(&json!({
"aliases": {}, "aliases": {},
@ -1346,6 +1452,7 @@ fn module_group() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
"source": foo_just,
}, },
}, },
"recipes": {}, "recipes": {},
@ -1370,9 +1477,11 @@ fn module_group() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
"source": source,
})) }))
.unwrap() .unwrap()
)) )
})
.run(); .run();
} }
@ -1383,6 +1492,8 @@ fn recipes_with_private_attribute_are_private() {
[private] [private]
foo: foo:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1426,7 +1537,9 @@ fn recipes_with_private_attribute_are_private() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source,
})
},
); );
} }
@ -1438,6 +1551,8 @@ fn doc_attribute_overrides_comment() {
[doc('ATTRIBUTE')] [doc('ATTRIBUTE')]
foo: foo:
", ",
|dir| {
let source = dir.join("justfile").to_str().unwrap().to_owned();
json!({ json!({
"aliases": {}, "aliases": {},
"assignments": {}, "assignments": {},
@ -1481,6 +1596,8 @@ fn doc_attribute_overrides_comment() {
}, },
"unexports": [], "unexports": [],
"warnings": [], "warnings": [],
}), "source": source
})
},
); );
} }

View File

@ -167,6 +167,11 @@ impl Test {
self self
} }
pub(crate) fn stdout_with_tempdir(mut self, stdout_fn: impl Fn(&TempDir) -> String) -> Self {
self.stdout = stdout_fn(&self.tempdir);
self
}
pub(crate) fn stdout_regex(mut self, stdout_regex: impl AsRef<str>) -> Self { pub(crate) fn stdout_regex(mut self, stdout_regex: impl AsRef<str>) -> Self {
self.stdout_regex = Some(Regex::new(&format!("^{}$", stdout_regex.as_ref())).unwrap()); self.stdout_regex = Some(Regex::new(&format!("^{}$", stdout_regex.as_ref())).unwrap());
self self