Skip to content

Commit

Permalink
tests: logs and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shramee committed Oct 31, 2023
1 parent 2a14753 commit f094403
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/scarb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, fs, path::PathBuf};
use std::{env::current_dir, fs, path::PathBuf};

use anyhow::Context;
use cairo_lang_test_plugin::TestCompilation;
Expand All @@ -10,19 +10,22 @@ use scarb::{
ops::{self, collect_metadata, CompileOpts, MetadataOptions},
};

pub fn prepare_crate_for_exercise(file_path: &PathBuf, crate_path: PathBuf) {
pub fn prepare_crate_for_exercise(file_path: &PathBuf) -> PathBuf {
let crate_path = current_dir().unwrap().join(PathBuf::from("runner-crate"));
let _ = fs::create_dir(crate_path.join("src"));
let lib_path = crate_path.join("src/lib.cairo");
match fs::copy(file_path, lib_path) {
let file_path = current_dir().unwrap().join(file_path);

match fs::copy(&file_path, &lib_path) {
Ok(_) => {}
Err(err) => panic!("Error occurred while preparing the exercise:\n {err:?}"),
Err(err) => panic!("Error occurred while preparing the exercise,\nExercise: {file_path:?}\nLib path: {lib_path:?}\n{err:?}"),
};
crate_path
}

pub fn scarb_build(file_path: &PathBuf) -> anyhow::Result<String> {
let path = env::current_dir().unwrap();
let (config, crate_path) = scarb_config(path.join(PathBuf::from("runner-crate")));

prepare_crate_for_exercise(file_path, crate_path);
let crate_path = prepare_crate_for_exercise(file_path);
let config = scarb_config(crate_path);

match compile(&config, false) {
Ok(_) => Ok("".into()),
Expand All @@ -31,10 +34,8 @@ pub fn scarb_build(file_path: &PathBuf) -> anyhow::Result<String> {
}

pub fn scarb_test(file_path: &PathBuf) -> anyhow::Result<String> {
let path = env::current_dir().unwrap();
let (config, crate_path) = scarb_config(path.join(PathBuf::from("runner-crate")));

prepare_crate_for_exercise(file_path, crate_path);
let crate_path = prepare_crate_for_exercise(file_path);
let config = scarb_config(crate_path);

let ws = ops::read_workspace(config.manifest_path(), &config)?;

Expand All @@ -49,7 +50,7 @@ pub fn scarb_test(file_path: &PathBuf) -> anyhow::Result<String> {
)
.unwrap();

let profile = env::var("SCARB_PROFILE").unwrap_or("dev".into());
let profile = "dev";
let default_target_dir = metadata.runtime_manifest.join("target");

let target_dir = metadata
Expand Down Expand Up @@ -88,12 +89,12 @@ pub fn scarb_test(file_path: &PathBuf) -> anyhow::Result<String> {
anyhow::Ok("".into())
}

pub fn scarb_config(crate_path: PathBuf) -> (Config, PathBuf) {
pub fn scarb_config(crate_path: PathBuf) -> Config {
let path = Utf8PathBuf::from_path_buf(crate_path.join(PathBuf::from("Scarb.toml"))).unwrap();

let config = Config::builder(path).build().unwrap();

(config, crate_path)
config
}

pub fn compile(config: &Config, test_targets: bool) -> anyhow::Result<()> {
Expand Down

0 comments on commit f094403

Please sign in to comment.