Gopher2600/logger/logger_test.go
JetSetIlly cd2a00d4ba logger.Log() and logger.Logf() now require a logger.Permission instance
the logger.Permission interface indicates whether the environment making
the logging request is allowed to create new log entries. the
environment.Environment type satisifies the Permission interface

logger.Allow is provided as a convienient way of indicating the the log
entry should always be created
2024-04-30 11:23:40 +01:00

65 lines
2 KiB
Go

// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
package logger_test
import (
"fmt"
"testing"
"github.com/jetsetilly/gopher2600/logger"
"github.com/jetsetilly/gopher2600/test"
)
func TestLogger(t *testing.T) {
tw := &test.Writer{}
logger.Write(tw)
test.ExpectEquality(t, tw.Compare(""), true)
logger.Log(logger.Allow, "test", "this is a test")
logger.Write(tw)
test.ExpectEquality(t, tw.Compare("test: this is a test\n"), true)
// clear the test.Writer buffer before continuing, makes comparisons easier
// to manage
tw.Clear()
logger.Log(logger.Allow, "test2", "this is another test")
logger.Write(tw)
test.ExpectEquality(t, tw.Compare("test: this is a test\ntest2: this is another test\n"), true)
// asking for too many entries in a Tail() should be okay
tw.Clear()
logger.Tail(tw, 100)
fmt.Println(tw)
test.ExpectEquality(t, tw.Compare("test: this is a test\ntest2: this is another test\n"), true)
// asking for exactly the correct number of entries is okay
tw.Clear()
logger.Tail(tw, 2)
test.ExpectEquality(t, tw.Compare("test: this is a test\ntest2: this is another test\n"), true)
// asking for fewer entries is okay too
tw.Clear()
logger.Tail(tw, 1)
test.ExpectEquality(t, tw.Compare("test2: this is another test\n"), true)
// and no entries
tw.Clear()
logger.Tail(tw, 0)
test.ExpectEquality(t, tw.Compare(""), true)
}