Сравнить коммиты

..

Нет общих коммитов. «main» и «v1.3.2» имеют совершенно разные истории.
main ... v1.3.2

8 изменённых файлов: 107 добавлений и 249 удалений

1
.gitignore предоставленный
Просмотреть файл

@ -6,6 +6,7 @@ Gopkg.toml
.DS_Store
.idea
.vscode
_artifacts

Просмотреть файл

@ -7,20 +7,20 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: outline
Background:
Given passing step
And passing step without return
Scenario Outline: parse a scenario
Given a feature path "<path>"
When I parse features
Then I should have <num> scenario registered
Examples:
| path | num |
| features/load.feature:3 | 0 |
@used
Examples:
| path | num |
@ -40,19 +40,19 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y
Scenario: four
Given a feature path "four"
@ -71,19 +71,19 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y @z
Scenario: four
Given a feature path "four"
@ -101,19 +101,19 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: tagged
@x
Scenario: one
Given a feature path "one"
@x
Scenario: two
Given a feature path "two"
@x @y
Scenario: three
Given a feature path "three"
@y @z
Scenario: four
Given a feature path "four"
@ -130,17 +130,17 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: f-tagged
Scenario: one
Given a feature path "one"
Scenario: two
Given a feature path "two"
@f
Scenario: three
Given a feature path "three"
@f
Scenario: four
Given a feature path "four"
@ -158,17 +158,17 @@ Feature: tag filters
Given a feature "normal.feature" file:
"""
Feature: f-tagged
Scenario: one
Given a feature path "one"
Scenario: two
Given a feature path "two"
@f
Scenario: three
Given a feature path "three"
@f
Scenario: four
Given a feature path "four"
@ -176,16 +176,16 @@ Feature: tag filters
And a feature "another.feature" file:
"""
Feature: non-tagged
Scenario: five
Given a feature path "five"
Scenario: six
Given a feature path "six"
Scenario: seven
Given a feature path "seven"
Scenario: eight
Given a feature path "eight"
"""
@ -197,31 +197,3 @@ Feature: tag filters
a feature path "three"
a feature path "four"
"""
Scenario: empty filter and scenarios with x-tag - are skipped
Given a feature "normal.feature" file:
"""
Feature: x-tagged
Scenario: one
Given a feature path "one"
Scenario: two
Given a feature path "two"
@x
Scenario: three
Given a feature path "three"
@x
Scenario: four
Given a feature path "four"
"""
When I run feature suite with tags ""
Then the suite should have passed
And I should have 2 scenario registered
And the following steps should be passed:
"""
a feature path "one"
a feature path "two"
"""

Просмотреть файл

@ -15,7 +15,7 @@ func ApplyTagFilter(filter string, pickles []*messages.Pickle) []*messages.Pickl
return ff
}
return filterOutX(pickles)
return pickles
}
var result = []*messages.Pickle{}
@ -77,14 +77,3 @@ func filterF(pickles []*messages.Pickle) []*messages.Pickle {
return result
}
func filterOutX(pickles []*messages.Pickle) []*messages.Pickle {
var result = []*messages.Pickle{}
for _, pickle := range pickles {
if !contains(pickle.Tags, "x") {
result = append(result, pickle)
}
}
return result
}

Просмотреть файл

@ -46,20 +46,18 @@ func (a *ASTer) ДобавитьШаг(шаг, f, ps string) error {
}
func (a *ASTer) найтиТестовыйФайл() error {
a.сгенеритьИмяФайла()
_, err := os.Stat(INIT_TEST_GO_FNAME)
if err != nil {
return err
}
имя, err := найтиТестовыйФайлВЭтойДире()
if err != nil {
return errors.Join(errors.New("Не могу найти *_test.go файл"), err)
}
a.pkg_test_go_fname = имя
_, err = os.Stat(a.pkg_test_go_fname)
return err
}
func (a *ASTer) сгенеритьИмяФайла() {
a.pkg_test_go_fname = a.pkg + "_test.go"
}
func (a *ASTer) добавитьШаг(шаг, f, ps string) error {
err := a.добавитьШагвInitФайл(шаг, f)
@ -254,7 +252,7 @@ func (a *ASTer) сконвертитьСтрокувПараметры(in string
}
func (a *ASTer) перезаписатьInitФайл() error {
err := забекапитьФайлСоВременем(INIT_TEST_GO_FNAME)
err := переименоватьФайлСоВременем(INIT_TEST_GO_FNAME)
if err != nil {
return errors.Join(err, errors.New("cant backup orig file"))
}
@ -268,7 +266,7 @@ func (a *ASTer) перезаписатьInitФайл() error {
return format.Node(f, a.init_test_fset, a.init_test_node)
}
func (a *ASTer) перезаписатьФайл() error {
err := забекапитьФайлСоВременем(a.pkg_test_go_fname)
err := переименоватьФайлСоВременем(a.pkg_test_go_fname)
if err != nil {
return errors.Join(err, errors.New("cant backup orig file"))
}

Просмотреть файл

@ -6,9 +6,9 @@
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -19,7 +19,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -29,10 +29,10 @@
То Файл "init_test.go" должен содержать:
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -43,76 +43,24 @@
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир() {
}
```
Сценарий: Добавление шага, с другим тестовым файлом
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
afterScenario()
return ctx, nil
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "system_test.go":
```
package mypkg
```
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с ""
То Файл "init_test.go" должен содержать:
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
afterScenario()
return ctx, nil
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "system_test.go" должен содержать:
```
package mypkg
func ПриветМир() {
}
```
Сценарий: Добавление шага с параметрами: int
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -123,7 +71,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -133,19 +81,19 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(arg1 int) {
}
```
Сценарий: Добавление шага с параметрами: int, string
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -156,7 +104,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -166,19 +114,19 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(arg1 int, arg2 string) {
}
```
Сценарий: Добавление шага с параметрами: string, int
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -189,7 +137,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -199,20 +147,20 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(arg1 string, arg2 int) {
}
```
Сценарий: Добавление шага к существующему
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`сделать чтото`, СделатьЧтото)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -223,26 +171,26 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
package mypkg
func СделатьЧтото(arg1 string, arg2 int) {
a := 1
}
```
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с "arg1 int"
То Файл "init_test.go" должен содержать:
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`сделать чтото`, СделатьЧтото)
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -253,28 +201,28 @@
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func СделатьЧтото(arg1 string, arg2 int) {
a := 1
}
func ПриветМир(arg1 int) {
}
```
Сценарий: Не добавляет если шаг с такой функцией уже есть
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -285,26 +233,26 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
package mypkg
func ПриветМир(arg1 string, arg2 int) {
a := 1
}
```
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с "arg1 int"
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с "arg1 int"
То Файл "init_test.go" должен содержать:
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -315,25 +263,25 @@
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(arg1 string, arg2 int) {
a := 1
}
```
Сценарий: Второй раз - не добавляет
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -344,22 +292,22 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
package mypkg
```
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с "arg1 int"
Когда Добавляется шаг: "^Привет Мир!$" с функцией "ПриветМир" с "arg1 int"
То Файл "init_test.go" должен содержать:
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^Привет Мир!$`, ПриветМир)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -370,24 +318,24 @@
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(arg1 int) {
}
```
Сценарий: Добавление шага с параметрами строкой
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -398,7 +346,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -408,19 +356,19 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(a int, s string, content *godog.DocString) {
}
```
Сценарий: Добавление шага с параметрами строкой с объединением по типу
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -431,7 +379,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -441,19 +389,19 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(a, b, c int) {
}
```
Сценарий: Добавление шага с параметрами строкой с объединением по типам
Дано Файл "init_test.go":
```
package mypkg
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
beforeScenario()
return ctx, nil
@ -464,7 +412,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -474,8 +422,8 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(a, b int, s1, s2 string) {
}
```

Просмотреть файл

@ -1,19 +1,10 @@
package ast
import "fmt"
// 0: имя, 1: тип
type Параметр []string
type Параметры []Параметр
func ДобавитьШаг(шаг, f string, ps string) error {
err := добавитьШаг(шаг, f, ps)
if err != nil {
fmt.Println("Ошибка добавления тестового шага:", err)
}
return err
}
func добавитьШаг(шаг, f string, ps string) error {
a, err := NewASTer()
if err != nil {
return err

Просмотреть файл

@ -5,7 +5,6 @@ import (
"go/ast"
"os"
"path/filepath"
"strings"
"time"
"errors"
@ -13,14 +12,10 @@ import (
"git.golang1.ru/softonik/godog/pkg/lib"
)
var (
BACKUP_DIR = "backup"
const (
BACKUP_DIR = ".back"
)
func init() {
BACKUP_DIR = os.TempDir() + "/godog/" + BACKUP_DIR
}
func получитьИмяGoПакетаВЭтойДире() (pkg_name string, err_ret error) {
err_ret = errors.New("not found")
@ -46,39 +41,12 @@ func получитьИмяGoПакетаВЭтойДире() (pkg_name string,
return
}
func найтиТестовыйФайлВЭтойДире() (name string, err_ret error) {
err_ret = errors.New("not found")
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), "_test.go") {
if info.Name() == "init_test.go" ||
strings.HasSuffix(info.Name(), "_mock_test.go") {
return nil
}
name = info.Name()
err_ret = nil
return filepath.SkipDir
}
return nil
})
if err != nil {
return "", err
}
return
}
func забекапитьФайлСоВременем(fname string) error {
func переименоватьФайлСоВременем(fname string) error {
os.MkdirAll(BACKUP_DIR, 0755)
currentTime := time.Now()
timestamp := currentTime.Format("20060102_150405")
new_fname := fmt.Sprintf(BACKUP_DIR+"/%v_%v", fname, timestamp)
return lib.CopyFile(fname, new_fname)
return os.Rename(fname, new_fname)
}
func являетсяЛиШагомсТакойЖеФункцией(stmt ast.Stmt, step *ast.ExprStmt) bool {

Просмотреть файл

@ -44,12 +44,3 @@ func CopyFile(src, dst string) (err error) {
return
}
func MoveFile(src, dst string) (err error) {
err = CopyFile(src, dst)
if err != nil {
return
}
return os.Remove(src)
}