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

Enable debug mode automatically #88

Merged
merged 2 commits into from Sep 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions minijinja/src/environment.rs
Expand Up @@ -299,9 +299,10 @@ impl<'env, 'source> Expression<'env, 'source> {
impl<'source> Environment<'source> {
/// Creates a new environment with sensible defaults.
///
/// This environment does not yet contain any templates but it will have all the
/// default filters loaded. If you do not want any default configuration you
/// can use the alternative [`empty`](Environment::empty) method.
/// This environment does not yet contain any templates but it will have all
/// the default filters, tests and globals loaded. If you do not want any
/// default configuration you can use the alternative
/// [`empty`](Environment::empty) method.
pub fn new() -> Environment<'source> {
Environment {
templates: Source::Borrowed(Default::default()),
Expand All @@ -310,14 +311,14 @@ impl<'source> Environment<'source> {
globals: RcType::new(functions::get_globals()),
default_auto_escape: RcType::new(default_auto_escape),
#[cfg(feature = "debug")]
debug: false,
debug: cfg!(debug_assertions),
}
}

/// Creates a completely empty environment.
///
/// This environment has no filters, no templates and no default logic for
/// auto escaping configured.
/// This environment has no filters, no templates, no globals and no default
/// logic for auto escaping configured.
pub fn empty() -> Environment<'source> {
Environment {
templates: Source::Borrowed(Default::default()),
Expand All @@ -326,7 +327,7 @@ impl<'source> Environment<'source> {
globals: RcType::default(),
default_auto_escape: RcType::new(no_auto_escape),
#[cfg(feature = "debug")]
debug: false,
debug: cfg!(debug_assertions),
}
}

Expand Down Expand Up @@ -363,7 +364,8 @@ impl<'source> Environment<'source> {
/// return a [`DebugInfo`](crate::error::DebugInfo) object from
/// [`Error::debug_info`](crate::error::Error::debug_info).
///
/// This requires the `debug` feature.
/// This requires the `debug` feature. This is enabled by default if
/// debug assertions are enabled and false otherwise.
#[cfg(feature = "debug")]
#[cfg_attr(docsrs, doc(cfg(feature = "debug")))]
pub fn set_debug(&mut self, enabled: bool) {
Expand Down
4 changes: 4 additions & 0 deletions minijinja/tests/test_templates.rs
Expand Up @@ -27,6 +27,10 @@ fn test_vm() {
let contents = std::fs::read_to_string(path).unwrap();
let mut iter = contents.splitn(2, "\n---\n");
let mut env = Environment::new();
#[cfg(feature = "debug")]
{
env.set_debug(false);
}
let ctx: serde_json::Value = serde_json::from_str(iter.next().unwrap()).unwrap();

for (path, source) in &refs {
Expand Down