How to use ParseSemVer method of types Package

Best Ginkgo code snippet using types.ParseSemVer

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

deprecation_support.go

Source: deprecation_support.go Github

copy
1package types
2
3import (
4	"os"
5	"strconv"
6	"strings"
7	"unicode"
8
9	"github.com/onsi/ginkgo/config"
10	"github.com/onsi/ginkgo/formatter"
11)
12
13type Deprecation struct {
14	Message string
15	DocLink string
16	Version string
17}
18
19type deprecations struct{}
20
21var Deprecations = deprecations{}
22
23func (d deprecations) CustomReporter() Deprecation {
24	return Deprecation{
25		Message: "You are using a custom reporter.  Support for custom reporters will likely be removed in V2.  Most users were using them to generate junit or teamcity reports and this functionality will be merged into the core reporter.  In addition, Ginkgo 2.0 will support emitting a JSON-formatted report that users can then manipulate to generate custom reports.\n\n{{red}}{{bold}}If this change will be impactful to you please leave a comment on {{cyan}}{{underline}}https://github.com/onsi/ginkgo/issues/711{{/}}",
26		DocLink: "removed-custom-reporters",
27		Version: "1.16.0",
28	}
29}
30
31func (d deprecations) V1Reporter() Deprecation {
32	return Deprecation{
33		Message: "You are using a V1 Ginkgo Reporter.  Please update your custom reporter to the new V2 Reporter interface.",
34		DocLink: "changed-reporter-interface",
35		Version: "1.16.0",
36	}
37}
38
39func (d deprecations) Async() Deprecation {
40	return Deprecation{
41		Message: "You are passing a Done channel to a test node to test asynchronous behavior.  This is deprecated in Ginkgo V2.  Your test will run synchronously and the timeout will be ignored.",
42		DocLink: "removed-async-testing",
43		Version: "1.16.0",
44	}
45}
46
47func (d deprecations) Measure() Deprecation {
48	return Deprecation{
49		Message: "Measure is deprecated and will be removed in Ginkgo V2.  Please migrate to gomega/gmeasure.",
50		DocLink: "removed-measure",
51		Version: "1.16.3",
52	}
53}
54
55func (d deprecations) Convert() Deprecation {
56	return Deprecation{
57		Message: "The convert command is deprecated in Ginkgo V2",
58		DocLink: "removed-ginkgo-convert",
59		Version: "1.16.0",
60	}
61}
62
63func (d deprecations) Blur() Deprecation {
64	return Deprecation{
65		Message: "The blur command is deprecated in Ginkgo V2.  Use 'ginkgo unfocus' instead.",
66		Version: "1.16.0",
67	}
68}
69
70type DeprecationTracker struct {
71	deprecations map[Deprecation][]CodeLocation
72}
73
74func NewDeprecationTracker() *DeprecationTracker {
75	return &DeprecationTracker{
76		deprecations: map[Deprecation][]CodeLocation{},
77	}
78}
79
80func (d *DeprecationTracker) TrackDeprecation(deprecation Deprecation, cl ...CodeLocation) {
81	ackVersion := os.Getenv("ACK_GINKGO_DEPRECATIONS")
82	if deprecation.Version != "" && ackVersion != "" {
83		ack := ParseSemVer(ackVersion)
84		version := ParseSemVer(deprecation.Version)
85		if ack.GreaterThanOrEqualTo(version) {
86			return
87		}
88	}
89
90	if len(cl) == 1 {
91		d.deprecations[deprecation] = append(d.deprecations[deprecation], cl[0])
92	} else {
93		d.deprecations[deprecation] = []CodeLocation{}
94	}
95}
96
97func (d *DeprecationTracker) DidTrackDeprecations() bool {
98	return len(d.deprecations) > 0
99}
100
101func (d *DeprecationTracker) DeprecationsReport() string {
102	out := formatter.F("{{light-yellow}}You're using deprecated Ginkgo functionality:{{/}}\n")
103	out += formatter.F("{{light-yellow}}============================================={{/}}\n")
104	out += formatter.F("Ginkgo 2.0 is under active development and will introduce (a small number of) breaking changes.\n")
105	out += formatter.F("To learn more, view the migration guide at {{cyan}}{{underline}}https://github.com/onsi/ginkgo/blob/v2/docs/MIGRATING_TO_V2.md{{/}}\n")
106	out += formatter.F("To comment, chime in at {{cyan}}{{underline}}https://github.com/onsi/ginkgo/issues/711{{/}}\n\n")
107
108	for deprecation, locations := range d.deprecations {
109		out += formatter.Fi(1, "{{yellow}}"+deprecation.Message+"{{/}}\n")
110		if deprecation.DocLink != "" {
111			out += formatter.Fi(1, "{{bold}}Learn more at:{{/}} {{cyan}}{{underline}}https://github.com/onsi/ginkgo/blob/v2/docs/MIGRATING_TO_V2.md#%s{{/}}\n", deprecation.DocLink)
112		}
113		for _, location := range locations {
114			out += formatter.Fi(2, "{{gray}}%s{{/}}\n", location)
115		}
116	}
117	out += formatter.F("\n{{gray}}To silence deprecations that can be silenced set the following environment variable:{{/}}\n")
118	out += formatter.Fi(1, "{{gray}}ACK_GINKGO_DEPRECATIONS=%s{{/}}\n", config.VERSION)
119	return out
120}
121
122type SemVer struct {
123	Major int
124	Minor int
125	Patch int
126}
127
128func (s SemVer) GreaterThanOrEqualTo(o SemVer) bool {
129	return (s.Major > o.Major) ||
130		(s.Major == o.Major && s.Minor > o.Minor) ||
131		(s.Major == o.Major && s.Minor == o.Minor && s.Patch >= o.Patch)
132}
133
134func ParseSemVer(semver string) SemVer {
135	out := SemVer{}
136	semver = strings.TrimFunc(semver, func(r rune) bool {
137		return !(unicode.IsNumber(r) || r == '.')
138	})
139	components := strings.Split(semver, ".")
140	if len(components) > 0 {
141		out.Major, _ = strconv.Atoi(components[0])
142	}
143	if len(components) > 1 {
144		out.Minor, _ = strconv.Atoi(components[1])
145	}
146	if len(components) > 2 {
147		out.Patch, _ = strconv.Atoi(components[2])
148	}
149	return out
150}
151
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in

Trigger ParseSemVer code on LambdaTest Cloud Grid

Execute automation tests with ParseSemVer on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)