2013-11-24 23:00:16 +00:00
|
|
|
/*
|
|
|
|
Copyright 2013 The Camlistore Authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2013-12-04 02:23:42 +00:00
|
|
|
"log"
|
2013-11-24 23:00:16 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BrokenTest marks the test as broken and calls t.Skip, unless the environment
|
|
|
|
// variable RUN_BROKEN_TESTS is set to 1 (or some other boolean true value).
|
|
|
|
func BrokenTest(t *testing.T) {
|
|
|
|
if v, _ := strconv.ParseBool(os.Getenv("RUN_BROKEN_TESTS")); !v {
|
|
|
|
t.Skipf("Skipping broken tests without RUN_BROKEN_TESTS=1")
|
|
|
|
}
|
|
|
|
}
|
2013-12-04 02:23:42 +00:00
|
|
|
|
|
|
|
// TLog changes the log package's output to log to t and returns a function
|
|
|
|
// to reset it back to stderr.
|
2014-08-25 23:43:34 +00:00
|
|
|
func TLog(t testing.TB) func() {
|
2013-12-04 02:23:42 +00:00
|
|
|
log.SetOutput(&twriter{t: t})
|
|
|
|
return func() {
|
|
|
|
log.SetOutput(os.Stderr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type twriter struct {
|
2014-10-19 14:44:14 +00:00
|
|
|
t testing.TB
|
2013-12-04 02:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *twriter) Write(p []byte) (n int, err error) {
|
2014-10-19 14:44:14 +00:00
|
|
|
t.Logf("%s", p)
|
2013-12-04 02:23:42 +00:00
|
|
|
}
|
2014-10-13 10:47:36 +00:00
|
|
|
|
|
|
|
// NewLogger returns a logger that logs to t with the given prefix.
|
|
|
|
func NewLogger(t *testing.T, prefix string) *log.Logger {
|
|
|
|
return log.New(&twriter{t: t}, prefix, log.LstdFlags)
|
|
|
|
}
|