Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 30, 2024
1 parent fa7cf3c commit bc7cf87
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Map;
Expand All @@ -32,7 +33,9 @@

import com.github.jlangch.venice.Parameters;
import com.github.jlangch.venice.Venice;
import com.github.jlangch.venice.VncException;
import com.github.jlangch.venice.impl.util.StringUtil;
import com.github.jlangch.venice.util.CapturingPrintStream;


public class TraceModuleTest {
Expand Down Expand Up @@ -87,6 +90,68 @@ public void test_trace() {
assertNull(venice.eval(script3, params));
}

@Test
public void test_trace_nested() {
final CapturingPrintStream cps = new CapturingPrintStream();

final Venice venice = new Venice();
final Map<String,Object> params = Parameters.of("*out*", cps);

final String script1 =
"(do \n" +
" (load-module :trace ['trace :as 't]) \n" +
" \n" +
" (defn foo [x] (+ x 2)) \n" +
" (defn bar [x] (foo x)) \n" +
" \n" +
" (t/trace-var +) \n" +
" (t/trace-var foo) \n" +
" (t/trace-var bar) \n" +
" \n" +
" (bar 5)) ";

assertEquals(7L, venice.eval(script1, params));
assertEquals(
"TRACE t00: (user/bar 5)\n" +
"TRACE t00: | (user/foo 5)\n" +
"TRACE t00: | | (core/+ 5 2)\n" +
"TRACE t00: | | | => 7\n" +
"TRACE t00: | | => 7\n" +
"TRACE t00: | => 7\n",
cps.getOutput().replaceAll("t[0-9]+:", "t00:"));
}

@Test
public void test_trace_exceptipn() {
final CapturingPrintStream cps = new CapturingPrintStream();

final Venice venice = new Venice();
final Map<String,Object> params = Parameters.of("*out*", cps);

final String script1 =
"(do \n" +
" (load-module :trace ['trace :as 't]) \n" +
" \n" +
" (defn foo [x] (/ x 0)) \n" +
" (defn bar [x] (foo x)) \n" +
" \n" +
" (t/trace-var /) \n" +
" (t/trace-var foo) \n" +
" (t/trace-var bar) \n" +
" \n" +
" (bar 5)) ";

assertThrows(VncException.class, () -> venice.eval(script1, params));
assertEquals(
"TRACE t00: (user/bar 5)\n" +
"TRACE t00: | (user/foo 5)\n" +
"TRACE t00: | | (core// 5 0)\n" +
"TRACE t00: | | | => com.github.jlangch.venice.VncException: / by zero\n" +
"TRACE t00: | | => com.github.jlangch.venice.VncException: / by zero\n" +
"TRACE t00: | => com.github.jlangch.venice.VncException: / by zero\n",
cps.getOutput().replaceAll("t[0-9]+:", "t00:"));
}

@Test
public void test_traceable() {
final Venice venice = new Venice();
Expand Down

0 comments on commit bc7cf87

Please sign in to comment.