Skip to content

Commit 9eacc65

Browse files
committed
Fix logging related err in status ref
1 parent 44a8974 commit 9eacc65

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Src/Details/Stateful/StatusRef.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ static status ToStatus(StatusRef? self)
3838

3939
internal static void SetLogData(AbstractDecorator dec,
4040
object target, string reason){
41+
if(!status.log) return;
4142
if(checkLogData && staticLogData.HasValue)
4243
throw new InvOp("Clear log data first");
4344
staticLogData = new LogData(dec, target, reason);
4445
}
4546

46-
// Only for testing; do not use.
47+
// Only for unit testing; do not use.
4748
internal static void ClearLogData() => staticLogData = null;
4849

4950
internal static status ToStatusWithLog(StatusRef? self){
@@ -53,6 +54,7 @@ internal static status ToStatusWithLog(StatusRef? self){
5354
ι.logData.scope,
5455
log && ι.logData.Reason());
5556
}else{
57+
if(!status.log) return hold;
5658
var scope = staticLogData.Value.scope;
5759
var reason = staticLogData.Value.Reason();
5860
if(scope == null) throw new InvOp("scope is null");

Tests/TestStatusRef.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ [Test] public void ToStatusWithLog([Values(true, false)] bool lg){
4848
StatusRef.ToStatusWithLog(x);
4949
}
5050

51-
[Test] public void ToStatusWithLog_badScope(){
51+
[Test] public void ToStatusWithLog_badScope([Values(true, false)] bool lg){
52+
status.log = lg;
5253
StatusRef.SetLogData(null, null, null);
53-
Assert.Throws<InvOp>( () => StatusRef.ToStatusWithLog(null) );
54+
if(status.log)
55+
Assert.Throws<InvOp>(
56+
() => StatusRef.ToStatusWithLog(null) );
5457
}
5558

5659
[Test] public void ToStatusWithLog_nullRef([Values(true, false)]

0 commit comments

Comments
 (0)