-
-
Notifications
You must be signed in to change notification settings - Fork 0
Implement e2e tests with testscript
#53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: govulncheck | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '2 2 * * 1' # Weekly on Monday | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| govulncheck: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: golang/govulncheck-action@v1 | ||
| with: | ||
| go-version-file: 'go.mod' | ||
| go-package: ./... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| export GOFLAGS=-mod=mod | ||
|
|
||
| .PHONY: FORCE | ||
| FORCE:; | ||
|
|
||
| .PHONY: vendor | ||
| vendor: | ||
| composer install --no-dev --prefer-dist | ||
| composer reinstall --prefer-dist '*' | ||
|
|
||
| bin: vendor | ||
|
|
||
| test-%: % | ||
| PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \ | ||
| go test -count=1 ./... | ||
|
|
||
| tests/data/releases-%.json: FORCE | ||
| curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | jq . > ./tests/data/releases-$*.json | ||
|
|
||
| resources/all-versions.json: bin tests/data/releases-5.json tests/data/releases-7.json tests/data/releases-8.json | ||
| ./bin/update-all-versions | ||
|
|
||
| --go-generate: | ||
| go generate ./... | ||
|
|
||
| txtar: resources/all-versions.json --go-generate | ||
| $(MAKE) UPDATE_SCRIPTS=1 test-bin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module github.com/typisttech/php-matrix | ||
|
|
||
| go 1.25.2 | ||
|
|
||
| require github.com/rogpeppe/go-internal v1.14.1 | ||
|
|
||
| require ( | ||
| golang.org/x/sys v0.26.0 // indirect | ||
| golang.org/x/tools v0.26.0 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= | ||
| github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= | ||
| golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= | ||
| golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
| golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= | ||
| golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package internal | ||
|
|
||
| var Constraints = []string{ | ||
| "^7", | ||
| "^7.1", | ||
| "^7.1.2", | ||
| "^7.1.2 || ~8.1.2", | ||
| "^7 ^7.2", | ||
| "*", | ||
| "@stable", | ||
| "^7@stable", | ||
| } | ||
|
|
||
| var Modes = []string{ | ||
| "", | ||
| "--mode=minor-only", | ||
| "--mode=full", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "text/template" | ||
|
|
||
| "github.com/typisttech/php-matrix/internal" | ||
| ) | ||
|
|
||
| const fileTemplateRaw = `# DO NOT EDIT THIS FILE | ||
| # This file is generated by "internal/composer/fail/main.go" | ||
| # Test the "{{ .Name }}" case | ||
|
|
||
| ! exec php-matrix composer {{ .Mode }} | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer {{ .Mode }} --source=auto | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer {{ .Mode }} --source=php.net | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer {{ .Mode }} --source=offline | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| -- stderr.golden -- | ||
|
|
||
| -- composer.json -- | ||
| {{ .ComposerJSON }} | ||
| ` | ||
|
|
||
| var rawCases = []rawData{ | ||
| {`no "require.php" is set/1`, `{"require":{"some/package":"^1.0"}}`}, | ||
| {`no "require.php" is set/2`, `{"require":{}}`}, | ||
| {`no "require.php" is set/3`, `{"require":123}`}, | ||
| {`no "require.php" is set/4`, `{"require-dev":{"php":"^1.0"}}`}, | ||
| {`no "require.php" is set/5`, `{"php":"^1.0"}`}, | ||
| {`no "require.php" is set/6`, `{}`}, | ||
|
|
||
| {`"require.php" is not a string/null`, `{"require":{"php":null}}`}, | ||
| {`"require.php" is not a string/object`, `{"require":{"php":{}}}`}, | ||
| {`"require.php" is not a string/array`, `{"require":{"php":[]}}`}, | ||
| {`"require.php" is not a string/integer`, `{"require":{"php":123}}`}, | ||
| {`"require.php" is not a string/float`, `{"require":{"php":12.3}}`}, | ||
| {`"require.php" is not a string/true`, `{"require":{"php":true}}`}, | ||
| {`"require.php" is not a string/false`, `{"require":{"php":false}}`}, | ||
|
|
||
| {`"require.php" is not a valid constraint/ruby`, `{"require":{"php":"~>1.0"}}`}, | ||
| {`"require.php" is not a valid constraint/empty string`, `{"require":{"php":""}}`}, | ||
| {`"require.php" is not a valid constraint/invalid string`, `{"require":{"php":"invalid constraint"}}`}, | ||
|
|
||
| {`unsatisfiable/1`, `{"require":{"php":">8.0 <7.0"}}`}, | ||
| {`unsatisfiable/2`, `{"require":{"php":">999"}}`}, | ||
| {`unsatisfiable/3`, `{"require":{"php":"dev-master"}}`}, | ||
|
|
||
| {`invalid json`, `{invalid json`}, | ||
| } | ||
|
|
||
| var fileTemplate = template.Must(template.New("").Parse(fileTemplateRaw)) | ||
|
|
||
| type rawData struct { | ||
| name string | ||
| ComposerJSON string | ||
| } | ||
|
|
||
| type data struct { | ||
| Mode string | ||
| rawData | ||
| } | ||
|
|
||
| func (d data) Name() string { | ||
| return d.name | ||
| } | ||
|
|
||
| func (d data) Write(f *os.File) error { | ||
| return fileTemplate.Execute(f, d) | ||
| } | ||
|
|
||
| func main() { | ||
| var cases []data | ||
| for _, mode := range internal.Modes { | ||
| for _, r := range rawCases { | ||
| cases = append(cases, data{ | ||
| Mode: mode, | ||
| rawData: r, | ||
| }) | ||
| } | ||
|
|
||
| err := internal.Generate("composer/fail", cases...) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package main_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/typisttech/php-matrix/internal" | ||
| ) | ||
|
|
||
| //go:generate go run ./main.go | ||
| func Test(t *testing.T) { | ||
| internal.RunTestscript(t) | ||
| } |
26 changes: 26 additions & 0 deletions
26
internal/composer/fail/testdata/_require.php__is_not_a_string_array.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # DO NOT EDIT THIS FILE | ||
| # This file is generated by "internal/composer/fail/main.go" | ||
| # Test the ""require.php" is not a string/array" case | ||
|
|
||
| ! exec php-matrix composer --mode=full | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=auto | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=php.net | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=offline | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| -- stderr.golden -- | ||
|
|
||
| [ERROR] The "require.php" field is not set or not a string. | ||
|
|
||
| -- composer.json -- | ||
| {"require":{"php":[]}} |
26 changes: 26 additions & 0 deletions
26
internal/composer/fail/testdata/_require.php__is_not_a_string_false.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # DO NOT EDIT THIS FILE | ||
| # This file is generated by "internal/composer/fail/main.go" | ||
| # Test the ""require.php" is not a string/false" case | ||
|
|
||
| ! exec php-matrix composer --mode=full | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=auto | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=php.net | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=offline | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| -- stderr.golden -- | ||
|
|
||
| [ERROR] The "require.php" field is not set or not a string. | ||
|
|
||
| -- composer.json -- | ||
| {"require":{"php":false}} |
26 changes: 26 additions & 0 deletions
26
internal/composer/fail/testdata/_require.php__is_not_a_string_float.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # DO NOT EDIT THIS FILE | ||
| # This file is generated by "internal/composer/fail/main.go" | ||
| # Test the ""require.php" is not a string/float" case | ||
|
|
||
| ! exec php-matrix composer --mode=full | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=auto | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=php.net | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| ! exec php-matrix composer --mode=full --source=offline | ||
| ! stdout . | ||
| cmp stderr stderr.golden | ||
|
|
||
| -- stderr.golden -- | ||
|
|
||
| [ERROR] The "require.php" field is not set or not a string. | ||
|
|
||
| -- composer.json -- | ||
| {"require":{"php":12.3}} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Unpinned tag for a non-immutable Action in workflow Medium