Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dojo-lang tests with default namespace #2422

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions crates/dojo-lang/src/plugin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use cairo_lang_defs::db::{DefsDatabase, DefsGroup};
use cairo_lang_defs::ids::ModuleId;
use cairo_lang_defs::plugin::MacroPlugin;
use cairo_lang_filesystem::cfg::CfgSet;
use cairo_lang_filesystem::cfg::{Cfg, CfgSet};
use cairo_lang_filesystem::db::{
init_files_group, AsFilesGroupMut, CrateConfiguration, FilesDatabase, FilesGroup, FilesGroupEx,
};
Expand All @@ -18,6 +18,8 @@ use cairo_lang_test_utils::parse_test_file::TestRunnerResult;
use cairo_lang_test_utils::verify_diagnostics_expectation;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use cairo_lang_utils::Upcast;
use dojo_world::config::namespace_config::DEFAULT_NAMESPACE_CFG_KEY;
use smol_str::SmolStr;

use super::BuiltinDojoPlugin;

Expand Down Expand Up @@ -90,11 +92,18 @@ pub fn test_expand_plugin_inner(
plugins.extend_from_slice(extra_plugins);
db.set_macro_plugins(plugins);

let cfg_set: Option<CfgSet> =
inputs.get("cfg").map(|s| serde_json::from_str(s.as_str()).unwrap());
if let Some(cfg_set) = cfg_set {
db.set_cfg_set(Arc::new(cfg_set));
}
// if no configuration is provided, be sure there is at least a default namespace,
// so all the tests have a correct configuration.
let cfg_set: CfgSet = match inputs.get("cfg") {
Some(cfg) => serde_json::from_str(cfg.as_str()).unwrap(),
None => {
let mut cfg_set = CfgSet::new();
cfg_set.insert(Cfg::kv(DEFAULT_NAMESPACE_CFG_KEY, SmolStr::from("dojo_test")));
cfg_set
}
};

db.set_cfg_set(Arc::new(cfg_set));

let test_id = &inputs["test_id"];
let cairo_code = &inputs["cairo_code"];
Expand Down
Loading
Loading