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

...

5 коммитов
v1.3.2 ... main

Автор SHA1 Сообщение Дата
Softonik
69e0676d93 Тестовый файл ищется в дире: *_test.go,
Некоторые проверки провалились
test / test (1.16.x) (push) Has been cancelled
test / test (1.17.x) (push) Has been cancelled
test / test (oldstable) (push) Has been cancelled
test / test (stable) (push) Has been cancelled
но не init_test.go и не на _mock_test.go
2025-07-10 22:35:01 +03:00
Softonik
8d882348a0 чистка 2025-07-10 22:33:01 +03:00
Softonik
3cfd1f25e9 AST: файлы в бекапную диру именно копируются 2025-06-28 13:06:00 +03:00
Softonik
a7166810c4 AST: бекапная дира: /tmp/gogen/backup/
Некоторые проверки провалились
test / test (1.16.x) (push) Has been cancelled
test / test (1.17.x) (push) Has been cancelled
test / test (oldstable) (push) Has been cancelled
test / test (stable) (push) Has been cancelled
2025-06-28 12:49:16 +03:00
Softonik
b5020fefd1 + Тесты с x-тегом пропускаются 2025-06-16 04:22:57 +03:00
8 изменённых файлов: 250 добавлений и 108 удалений

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

@ -6,7 +6,6 @@ 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,3 +197,31 @@ 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 pickles
return filterOutX(pickles)
}
var result = []*messages.Pickle{}
@ -77,3 +77,14 @@ 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,18 +46,20 @@ 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 = os.Stat(a.pkg_test_go_fname)
имя, err := найтиТестовыйФайлВЭтойДире()
if err != nil {
return errors.Join(errors.New("Не могу найти *_test.go файл"), err)
}
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)
@ -252,7 +254,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"))
}
@ -266,7 +268,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,24 +43,24 @@
})
InitializeGomegaForGodog(ctx)
}
```
То Файл "mypkg_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
@ -71,7 +71,59 @@
})
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
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
afterScenario()
return ctx, nil
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -81,19 +133,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
@ -104,7 +156,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -114,19 +166,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
@ -137,7 +189,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -147,20 +199,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
@ -171,26 +223,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
@ -201,28 +253,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
@ -233,26 +285,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
@ -263,25 +315,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
@ -292,22 +344,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
@ -318,24 +370,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
@ -346,7 +398,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -356,19 +408,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
@ -379,7 +431,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -389,19 +441,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
@ -412,7 +464,7 @@
})
InitializeGomegaForGodog(ctx)
}
```
Дано Файл "mypkg_test.go":
```
@ -422,8 +474,8 @@
То Файл "mypkg_test.go" должен содержать:
```
package mypkg
func ПриветМир(a, b int, s1, s2 string) {
}
```

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

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

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

@ -44,3 +44,12 @@ 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)
}