Skip to content

Commit

Permalink
Advertise Ginkgo 2.0. Introduce deprecations.
Browse files Browse the repository at this point in the history
- Update README.md to advertise that Ginkgo 2.0 is coming.
- Backport the 2.0 DeprecationTracker and start alerting users
about upcoming deprecations.
  • Loading branch information
onsi committed Apr 3, 2021
1 parent 9162b86 commit 9ef1913
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Jump to the [docs](https://onsi.github.io/ginkgo/) | [中文文档](https://ke-c

If you have a question, comment, bug report, feature request, etc. please open a GitHub issue, or visit the [Ginkgo Slack channel](https://app.slack.com/client/T029RQSE6/CQQ50BBNW).

# Ginkgo 2.0 is coming soon!

An effort is underway to develop and deliver Ginkgo 2.0. The work is happening in the [v2](https://github.com/onsi/ginkgo/tree/v2) branch and a changelog and migration guide is being maintained on that branch [here](https://github.com/onsi/ginkgo/blob/v2/docs/MIGRATING_TO_V2.md). Issue [#711](https://github.com/onsi/ginkgo/issues/711) is the central place for discussion and links to the original [proposal doc](https://docs.google.com/document/d/1h28ZknXRsTLPNNiOjdHIO-F2toCzq4xoZDXbfYaBdoQ/edit#).

As described in the [changelog](https://github.com/onsi/ginkgo/blob/v2/docs/MIGRATING_TO_V2.md) and [proposal](https://docs.google.com/document/d/1h28ZknXRsTLPNNiOjdHIO-F2toCzq4xoZDXbfYaBdoQ/edit#), Ginkgo 2.0 will clean up the Ginkgo codebase, deprecate and remove some v1 functionality, and add several new much-requested features. To help users get ready for the migration, Ginkgo v1 has started emitting deprecation warnings for features that will no longer be supported with links to documentation for how to migrate away from these features. If you have concerns or comments please chime in on [#711](https://github.com/onsi/ginkgo/issues/711).

The current timeline for completion of 2.0 looks like:

- Early April 2021: first public release of 2.0, deprecation warnings land in v1.
- May 2021: first beta/rc of 2.0 with most new functionality in place.
- June/July 2021: 2.0 ships and fully replaces the 1.x codebase on master.

## TLDR
Ginkgo builds on Go's `testing` package, allowing expressive [Behavior-Driven Development](https://en.wikipedia.org/wiki/Behavior-driven_development) ("BDD") style tests.
It is typically (and optionally) paired with the [Gomega](https://github.com/onsi/gomega) matcher library.
Expand Down
190 changes: 190 additions & 0 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package formatter

import (
"fmt"
"regexp"
"strings"
)

const COLS = 80

type ColorMode uint8

const (
ColorModeNone ColorMode = iota
ColorModeTerminal
ColorModePassthrough
)

var SingletonFormatter = New(ColorModeTerminal)

func F(format string, args ...interface{}) string {
return SingletonFormatter.F(format, args...)
}

func Fi(indentation uint, format string, args ...interface{}) string {
return SingletonFormatter.Fi(indentation, format, args...)
}

func Fiw(indentation uint, maxWidth uint, format string, args ...interface{}) string {
return SingletonFormatter.Fiw(indentation, maxWidth, format, args...)
}

type Formatter struct {
ColorMode ColorMode
colors map[string]string
styleRe *regexp.Regexp
preserveColorStylingTags bool
}

func NewWithNoColorBool(noColor bool) Formatter {
if noColor {
return New(ColorModeNone)
}
return New(ColorModeTerminal)
}

func New(colorMode ColorMode) Formatter {
f := Formatter{
ColorMode: colorMode,
colors: map[string]string{
"/": "\x1b[0m",
"bold": "\x1b[1m",
"underline": "\x1b[4m",

"red": "\x1b[38;5;9m",
"orange": "\x1b[38;5;214m",
"coral": "\x1b[38;5;204m",
"magenta": "\x1b[38;5;13m",
"green": "\x1b[38;5;10m",
"dark-green": "\x1b[38;5;28m",
"yellow": "\x1b[38;5;11m",
"light-yellow": "\x1b[38;5;228m",
"cyan": "\x1b[38;5;14m",
"gray": "\x1b[38;5;243m",
"light-gray": "\x1b[38;5;246m",
"blue": "\x1b[38;5;12m",
},
}
colors := []string{}
for color := range f.colors {
colors = append(colors, color)
}
f.styleRe = regexp.MustCompile("{{(" + strings.Join(colors, "|") + ")}}")
return f
}

func (f Formatter) F(format string, args ...interface{}) string {
return f.Fi(0, format, args...)
}

func (f Formatter) Fi(indentation uint, format string, args ...interface{}) string {
return f.Fiw(indentation, 0, format, args...)
}

func (f Formatter) Fiw(indentation uint, maxWidth uint, format string, args ...interface{}) string {
out := fmt.Sprintf(f.style(format), args...)

if indentation == 0 && maxWidth == 0 {
return out
}

lines := strings.Split(out, "\n")

if maxWidth != 0 {
outLines := []string{}

maxWidth = maxWidth - indentation*2
for _, line := range lines {
if f.length(line) <= maxWidth {
outLines = append(outLines, line)
continue
}
outWords := []string{}
length := uint(0)
words := strings.Split(line, " ")
for _, word := range words {
wordLength := f.length(word)
if length+wordLength <= maxWidth {
length += wordLength
outWords = append(outWords, word)
continue
}
outLines = append(outLines, strings.Join(outWords, " "))
outWords = []string{word}
length = wordLength
}
if len(outWords) > 0 {
outLines = append(outLines, strings.Join(outWords, " "))
}
}

lines = outLines
}

if indentation == 0 {
return strings.Join(lines, "\n")
}

padding := strings.Repeat(" ", int(indentation))
for i := range lines {
if lines[i] != "" {
lines[i] = padding + lines[i]
}
}

return strings.Join(lines, "\n")
}

func (f Formatter) length(styled string) uint {
n := uint(0)
inStyle := false
for _, b := range styled {
if inStyle {
if b == 'm' {
inStyle = false
}
continue
}
if b == '\x1b' {
inStyle = true
continue
}
n += 1
}
return n
}

func (f Formatter) CycleJoin(elements []string, joiner string, cycle []string) string {
if len(elements) == 0 {
return ""
}
n := len(cycle)
out := ""
for i, text := range elements {
out += cycle[i%n] + text
if i < len(elements)-1 {
out += joiner
}
}
out += "{{/}}"
return f.style(out)
}

func (f Formatter) style(s string) string {
switch f.ColorMode {
case ColorModeNone:
return f.styleRe.ReplaceAllString(s, "")
case ColorModePassthrough:
return s
case ColorModeTerminal:
return f.styleRe.ReplaceAllStringFunc(s, func(match string) string {
if out, ok := f.colors[strings.Trim(match, "{}")]; ok {
return out
}
return match
})
}

return ""
}
6 changes: 6 additions & 0 deletions ginkgo/convert_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"

"github.com/onsi/ginkgo/ginkgo/convert"
colorable "github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable"
"github.com/onsi/ginkgo/types"
)

func BuildConvertCommand() *Command {
Expand All @@ -21,6 +23,10 @@ func BuildConvertCommand() *Command {
}

func convertPackage(args []string, additionalArgs []string) {
deprecationTracker := types.NewDeprecationTracker()
deprecationTracker.TrackDeprecation(types.Deprecations.Convert())
fmt.Fprintln(colorable.NewColorableStderr(), deprecationTracker.DeprecationsReport())

if len(args) != 1 {
println(fmt.Sprintf("usage: ginkgo convert /path/to/your/package"))
os.Exit(1)
Expand Down
21 changes: 21 additions & 0 deletions ginkgo/run_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/ginkgo/interrupthandler"
"github.com/onsi/ginkgo/ginkgo/testrunner"
colorable "github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable"
"github.com/onsi/ginkgo/types"
)

Expand Down Expand Up @@ -53,6 +54,26 @@ func (r *SpecRunner) RunSpecs(args []string, additionalArgs []string) {
r.commandFlags.computeNodes()
r.notifier.VerifyNotificationsAreAvailable()

deprecationTracker := types.NewDeprecationTracker()

if r.commandFlags.ParallelStream {
deprecationTracker.TrackDeprecation(types.Deprecation{
Message: "--stream is deprecated and will be removed in Ginkgo 2.0",
DocLink: "removed--stream",
})
}

if r.commandFlags.Notify {
deprecationTracker.TrackDeprecation(types.Deprecation{
Message: "--notify is deprecated and will be removed in Ginkgo 2.0",
DocLink: "removed--notify",
})
}

if deprecationTracker.DidTrackDeprecations() {
fmt.Fprintln(colorable.NewColorableStderr(), deprecationTracker.DeprecationsReport())
}

suites, skippedPackages := findSuites(args, r.commandFlags.Recurse, r.commandFlags.SkipPackage, true)
if len(skippedPackages) > 0 {
fmt.Println("Will skip:")
Expand Down
Loading

0 comments on commit 9ef1913

Please sign in to comment.