From 9d00b9ddaee0d5bac09a428b1974336845038423 Mon Sep 17 00:00:00 2001 From: lukechampine Date: Sun, 3 Apr 2016 12:41:38 -0400 Subject: add TestPanic and TestReadWritten 100% test coverage! --- stm_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'stm_test.go') diff --git a/stm_test.go b/stm_test.go index 2542894..44ca40b 100644 --- a/stm_test.go +++ b/stm_test.go @@ -177,6 +177,28 @@ func TestCompose(t *testing.T) { } } +func TestPanic(t *testing.T) { + defer func() { + if recover() == nil { + t.Fatal("expected panic, got nil") + } + }() + // normal panics should escape Atomically + Atomically(func(*Tx) { + panic("foo") + }) +} + +func TestReadWritten(t *testing.T) { + // reading a variable written in the same transaction should return the + // previously written value + x := NewVar(3) + Atomically(func(tx *Tx) { + tx.Set(x, 5) + tx.Assert(tx.Get(x).(int) == 5) + }) +} + func BenchmarkAtomicGet(b *testing.B) { x := NewVar(0) for i := 0; i < b.N; i++ { -- cgit v1.2.3