diff --git a/.buildbot.sh b/.buildbot.sh index 11b67f2a..cb6361e3 100644 --- a/.buildbot.sh +++ b/.buildbot.sh @@ -34,6 +34,8 @@ cargo +alloy test --release cargo +alloy run -- --cp SOM/Smalltalk SOM/TestSuite/TestHarness.som cargo +alloy run --release -- --cp SOM/Smalltalk SOM/TestSuite/TestHarness.som +cargo +alloy run --release -- --cp SOM/Smalltalk:lang_tests hello_world1 + cd SOM cargo +alloy run --release -- \ --cp Smalltalk:TestSuite:SomSom/src/compiler:SomSom/src/vm:SomSom/src/vmobjects:SomSom/src/interpreter:SomSom/src/primitives \ diff --git a/src/main.rs b/src/main.rs index 9b04d1ea..1987cf03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,12 +30,13 @@ fn usage(prog: &str) -> ! { .file_name() .map(|x| x.to_str().unwrap_or("yksom")) .unwrap_or("yksom"); - writeln!( - &mut stderr(), - "Usage: {} [-h] --cp [-- [... ]]", - leaf - ) - .ok(); + error(&format!( + "Usage: {leaf} [-h] --cp [-- [... ]]" + )); +} + +fn error(msg: &str) -> ! { + stderr().write_all(msg.as_bytes()).ok(); process::exit(1) } @@ -56,18 +57,39 @@ fn main() { usage(prog); } - let src_path = &Path::new(&matches.free[0]).canonicalize().unwrap(); - let mut cp = match src_path.parent() { - Some(p) => vec![p.to_owned()], - None => vec![], + let mut cp: Vec<_> = matches + .opt_str("cp") + .unwrap() + .split(":") + .map(|x| PathBuf::from_str(x).unwrap()) + .collect(); + + let mut src_path = Path::new(&matches.free[0]).to_owned(); + if !src_path.is_file() && src_path.extension().is_none() { + for d in &cp { + let mut p = PathBuf::new(); + p.push(d); + p.push(&matches.free[0]); + p.set_extension("som"); + if p.is_file() { + src_path = p; + } + } + if !src_path.is_file() { + error(&format!( + "{} does not exist or is not a file", + &matches.free[0] + )); + } + } + let src_path = match src_path.canonicalize() { + Ok(s) => s, + Err(e) => error(&format!("Can't canonicalise {}: {}", &matches.free[0], e)), }; - cp.extend( - matches - .opt_str("cp") - .unwrap() - .split(":") - .map(|x| PathBuf::from_str(x).unwrap()), - ); + + if let Some(p) = src_path.parent() { + cp.insert(0, p.to_owned()); + } let mut vm = VM::new(cp); let system = vm.get_global_or_nil("system");