コード例 #1
0
ファイル: exception_test.go プロジェクト: simulatedsimian/meh
func TestThrow(t *testing.T) {
	extype, finallyCalled := testEx1(func() { Throw(5) })
	assert.Equal(t, extype, reflect.TypeOf(5))
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() { Throw("bang") })
	assert.Equal(t, extype, reflect.TypeOf("bang"))
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() { Throw(errors.New("bang")) })
	assert.Equal(t, extype, errorType)
	assert.True(t, finallyCalled)

	extype, finallyCalled = testEx1(func() {})
	assert.Nil(t, extype)
	assert.True(t, finallyCalled)

	assert.MustPanic(t, func(t *testing.T) {
		testEx1(func() {
			Throw(empty{})
		})
	})

	assert.MustPanic(t, func(t *testing.T) {
		Try(func() {
		}).Catch(func(e int) {
		}).Finally(func() {
			Throw("asdf")
		})
	})

	Try(func() {
		Throw(5)
	}).Catch(func(e int, e2 int) {
		assert.True(t, false) // should not get here
	}).Catch(func(e int) {
	}).Finally(func() {
	})
}
コード例 #2
0
func TestExec(t *testing.T) {
	assert.Nil(t, execWithTimeout("dummyproc", "", "", os.Stdout, 100*time.Second))
	assert.Nil(t, execWithTimeout("dummyproc", "5", "", os.Stdout, 100*time.Second))
	assert.NotNil(t, execWithTimeout("dummyproc", "5", "", os.Stdout, 1*time.Second))
	assert.NotNil(t, execWithTimeout("dummyproc", "5 1", "", os.Stdout, 100*time.Second))
}