-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.sh
More file actions
executable file
·37 lines (24 loc) · 1.38 KB
/
convert.sh
File metadata and controls
executable file
·37 lines (24 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /bin/bash
filename="${1}"
#Ginkgo has a custom style to start the tests where as GoConvey simply requires a pure go Test method
sed -i -E 's/var _ = Describe\("([^")]+)".*$/func Test\1\(t *testing.T\){\n\tConvey("\1", t, func(){/g' ${filename}
lastline=`cat ${filename}| tail -n1`
if [ ! "$lastline" == "}" ]; then
echo "}" >> ${filename}
fi
#The different test structure methods of Ginkgo replaced with the only one for GoConvey
sed -i -E 's/Describe\(\"|Context\(\"|It\(\"/Convey(\"/g' ${filename}
#The different pending test structures of Ginkgo replace with the only one for GoConvey
sed -i -E 's/PDescribe\(\"|PContext\(\"|PIt\(\"/SkipConvey(\"/g' ${filename}
#Assertions with GoConvey start with So(...), Ginkgo has an Expect method aswell as others
# but this project only uses the Expect method.
sed -i -E 's/Expect/So/g' ${filename}
#Migrating those assertions for To(Equal(...))
sed -i -E 's/\)\.To\(Equal\(([^\)]+)\)\)/, ShouldEqual, \1\)/g' ${filename}
#Migrating those assertions for To(BeNil())
sed -i -E 's/\)\.To\(BeNil\(\)\)/, ShouldBeNil)/g' ${filename}
sed -i -E 's/\. \"github.com\/onsi\/ginkgo\"/\. \"github.com\/smartystreets\/goconvey\/convey\"/g' ${filename}
sed -i -E 's/\. \"github.com\/onsi\/gomega\"//g' ${filename}
goimports -w ${filename}
#This feels like a useful thing to remember for the future. Multiline grep
#grep -Poz "(?s)import \([^\)]+\)" ${filename}