Skip to content

Commit

Permalink
unittest to make sure everything is set right
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Jan 26, 2015
1 parent 197725e commit 5ee9d87
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
31 changes: 20 additions & 11 deletions std/experimental/logger/core.d
Expand Up @@ -107,13 +107,13 @@ bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL,
}

/** This template returns the $(D LogLevel) named "logLevel" of type $(D
LogLevel) defined in a user defined module where the filename has the
LogLevel) defined in a user defined module where the filename has the
suffix "_loggerconfig.d". This $(D LogLevel) sets the minimal $(D LogLevel)
of the module.
A minimal $(D LogLevel) can be defined on a per module basis.
In order to define a module $(D LogLevel) a file with a modulename
"MODULENAME_loggerconfig" must be found. If no such module exists and the
"MODULENAME_loggerconfig" must be found. If no such module exists and the
module is a nested module, it is checked if there exists a
"PARENT_MODULE_loggerconfig" module with such a symbol.
If this module exists and it contains a $(D LogLevel) called logLevel this $(D
Expand Down Expand Up @@ -2946,15 +2946,6 @@ private void trustedStore(T)(ref shared T dst, ref T src) @trusted
atomicStore!(MemoryOrder.rel)(dst, src);
}

@safe unittest
{
stdThreadLocalLog.logLevel = LogLevel.all;
auto dl = cast(FileLogger)sharedLog;
assert(dl !is null);
assert(dl.logLevel == LogLevel.all);
assert(globalLogLevel == LogLevel.all);
}

// check that thread-local logging does not propagate
// to shared logger
unittest
Expand Down Expand Up @@ -2993,6 +2984,12 @@ unittest
}
}

auto oldSharedLog = sharedLog;
scope(exit)
{
sharedLog = oldSharedLog;
}

sharedLog = new IgnoredLog;
Thread[] spawned;

Expand All @@ -3010,3 +3007,15 @@ unittest

assert (atomicOp!"=="(logged_count, 4));
}

@safe unittest
{
auto dl = cast(FileLogger)sharedLog;
assert(dl !is null);
assert(dl.logLevel == LogLevel.all);
assert(globalLogLevel == LogLevel.all);

auto tl = cast(StdForwardLogger)stdThreadLocalLog;
assert(tl !is null);
stdThreadLocalLog.logLevel = LogLevel.all;
}
8 changes: 6 additions & 2 deletions std/experimental/logger/filelogger.d
Expand Up @@ -189,10 +189,14 @@ unittest
file.close();
}

unittest
@safe unittest
{
auto dl = sharedLog;
auto dl = cast(FileLogger)sharedLog;
assert(dl !is null);
assert(dl.logLevel == LogLevel.all);
assert(globalLogLevel == LogLevel.all);

auto tl = cast(StdForwardLogger)stdThreadLocalLog;
assert(tl !is null);
stdThreadLocalLog.logLevel = LogLevel.all;
}
9 changes: 6 additions & 3 deletions std/experimental/logger/multilogger.d
Expand Up @@ -72,7 +72,7 @@ class MultiLogger : Logger
import std.range.interfaces : back, popBack;
for (size_t i = 0; i < this.logger.length; ++i)
{
if (this.logger[i].name == toRemove)
if (this.logger[i].name == toRemove)
{
Logger ret = this.logger[i].logger;
this.logger[i] = this.logger.back();
Expand Down Expand Up @@ -184,9 +184,12 @@ unittest

@safe unittest
{
auto dl = sharedLog;
auto dl = cast(FileLogger)sharedLog;
assert(dl !is null);
assert(dl.logLevel == LogLevel.all);
assert(globalLogLevel == LogLevel.all);
}

auto tl = cast(StdForwardLogger)stdThreadLocalLog;
assert(tl !is null);
stdThreadLocalLog.logLevel = LogLevel.all;
}

0 comments on commit 5ee9d87

Please sign in to comment.