Skip to content

Commit ede7aa8

Browse files
committed
add logging test
1 parent 399a058 commit ede7aa8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/pos/inline-logging.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
object Config {
2+
inline val logging = true
3+
}
4+
5+
object Logger {
6+
7+
private var indent = 0
8+
9+
inline def log[T](msg: => String, indentMargin: Int)(op: => T): T =
10+
if (Config.logging) {
11+
val msgVal = msg
12+
println(s"${" " * indent}start $msgVal")
13+
indent += indentMargin
14+
val result = op
15+
indent -= indentMargin
16+
println(s"${" " * indent}$msgVal = $result")
17+
result
18+
}
19+
else op
20+
}
21+
import Logger._
22+
23+
var indentSetting = 2
24+
25+
def factorial(n: BigInt): BigInt = {
26+
log(s"factorial($n)", indentSetting) {
27+
if (n == 0) 1
28+
else n * factorial(n - 1)
29+
}
30+
}

0 commit comments

Comments
 (0)