Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/frontend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{
rc::Rc,
};

use anyhow::bail;

use crate::{
codegen::{
build::build_impl,
Expand All @@ -19,7 +21,12 @@ use crate::{
pub fn build(input: Option<PathBuf>, output: Option<PathBuf>) -> anyhow::Result<Artifact> {
let input = input.unwrap_or_else(|| env::current_dir().unwrap());
let canonical_input = input.canonicalize()?;
let project_name = canonical_input.file_name().unwrap().to_str().unwrap();
let Some(project_name) = canonical_input.file_name().and_then(|name| name.to_str()) else {
bail!(
"{} is not a valid project directory",
canonical_input.display()
);
};
let output = output.unwrap_or_else(|| input.join(format!("{project_name}.sb3")));
let fs = Rc::new(RefCell::new(RealFS));
let sb3 = Sb3::new(
Expand All @@ -29,3 +36,18 @@ pub fn build(input: Option<PathBuf>, output: Option<PathBuf>) -> anyhow::Result<
);
build_impl(fs, canonical_input, sb3, None)
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use super::build;

#[test]
fn test_build_root_dir_errors_without_panic() {
match build(Some(PathBuf::from("/")), None) {
Ok(_) => panic!("building the filesystem root should return an error"),
Err(err) => assert!(err.to_string().contains("not a valid project directory")),
}
}
}
Loading