Skip to content

Commit

Permalink
Enable debug mode automatically (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Sep 2, 2022
1 parent 7ff7b91 commit 669e4d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit 669e4d4

Please sign in to comment.