mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
Fix handling of config file (#2996)
This commit is contained in:
parent
7f90b7826d
commit
560edc536c
1 changed files with 25 additions and 1 deletions
|
@ -22,6 +22,7 @@ use ring;
|
|||
use std::collections::HashSet;
|
||||
use std::fmt::Write;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::str;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
@ -60,7 +61,20 @@ impl CompilerConfig {
|
|||
// Convert the PathBuf to a canonicalized string. This is needed by the
|
||||
// compiler to properly deal with the configuration.
|
||||
let config_path = match &config_file {
|
||||
Some(config_file) => Some(config_file.canonicalize().unwrap().to_owned()),
|
||||
Some(config_file) => Some(
|
||||
config_file
|
||||
.canonicalize()
|
||||
.map_err(|_| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"Could not find the config file: {}",
|
||||
config_file.to_string_lossy()
|
||||
),
|
||||
)
|
||||
})?
|
||||
.to_owned(),
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -773,4 +787,14 @@ mod tests {
|
|||
assert_eq!(config.compile_js, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compiler_config_load() {
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
let temp_dir_path = temp_dir.path();
|
||||
let path = temp_dir_path.join("doesnotexist.json");
|
||||
let path_str = path.to_str().unwrap().to_string();
|
||||
let res = CompilerConfig::load(Some(path_str.clone()));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue