Skip to content

Commit

Permalink
Runner test suite things (#132)
Browse files Browse the repository at this point in the history
* It... works???

* Making things nice

* Add runner test action and job to verify suite
  • Loading branch information
UnstoppableMango authored Jun 8, 2024
1 parent 4649cef commit 98e1351
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 22 deletions.
24 changes: 24 additions & 0 deletions .github/actions/runner-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Execute runner tests
description: Execute the runner test suite against a given runner binary.

inputs:
path:
description: The path to the runner binary.
required: true

runs:
using: composite
steps:
- name: Build runner test
uses: ./.github/actions/build-cs
with:
path: src/RunnerTest
configuration: Release

- name: Execute runner tests on ${{ inputs.path }}
shell: bash
run: |
dotnet run \
--project src/RunnerTest \
--configuration Release \
${{ inputs.path }}
16 changes: 16 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
token: ${{ secrets.GITHUB_TOKEN }}

verify-runner-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: ./.github/actions/build-go
with:
path: cli/echo
gomod: cli/go.mod

- name: Verify runner tests
uses: ./.github/actions/runner-test
with:
path: cli/echo/bin/echo

goreleaser:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ CLI_BIN := $(CLI_DIR)/$(BIN_PATH)/um.dll
LANG_DIR := src/Language
LANG_SRC := $(shell find $(LANG_DIR) -name '*.fs' -not -path '*obj*' -type f)

RUNNER_TEST_DIR := src/RunnerTest
RUNNER_TEST_SRC := $(shell find $(RUNNER_TEST_DIR) -name '*.fs' -not -path '*obj*' -type f)
RUNNER_TEST_BIN := $(RUNNER_TEST_DIR)/$(BIN_PATH)/$(NS).RunnerTest.dll

ECHO_SRC := $(shell find cli/echo -type f -name '*.go')
ECHO_CLI := cli/echo/bin/echo

.PHONY: build build_dotnet
build: build_dotnet cli docker pkg
@touch .make/build_lang
Expand All @@ -37,9 +44,8 @@ test_dotnet: build_dotnet
dotnet test --no-build
test_packages:
@$(MAKE) -C packages test
echo_test:
@$(MAKE) -C cli/echo
dotnet run --project src/RunnerTest cli/echo/bin/echo
echo_test: $(ECHO_CLI) $(RUNNER_TEST_BIN)
@dotnet ${RUNNER_TEST_BIN} ${ECHO_CLI}

.PHONY: gen
gen: gen_proto
Expand Down Expand Up @@ -101,6 +107,12 @@ undev:
.PHONY: work
work: go.work go.work.sum

$(ECHO_CLI): $(ECHO_SRC)
@$(MAKE) -C cli/echo --no-print-directory

$(RUNNER_TEST_BIN): $(RUNNER_TEST_SRC)
dotnet build ${RUNNER_TEST_DIR}

go.work: GOWORK :=
go.work:
go work init
Expand Down
2 changes: 1 addition & 1 deletion cli/echo/cmd/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
rootCmd.AddCommand(fromCmd)
}

type echoConverter struct {}
type echoConverter struct{}

// From implements uml.Converter.
func (e echoConverter) From(ctx context.Context, reader io.Reader) (*tdl.Spec, error) {
Expand Down
5 changes: 2 additions & 3 deletions cli/echo/cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ func init() {
rootCmd.AddCommand(genCmd)
}

type echoGenerator struct {
}
type echoGenerator struct{}

// Gen implements uml.Generator.
func (e echoGenerator) Gen(ctx context.Context, spec *tdlv1alpha1.Spec, writer io.Writer) error {
Expand All @@ -24,7 +23,7 @@ func (e echoGenerator) Gen(ctx context.Context, spec *tdlv1alpha1.Spec, writer i
return err
}

_, err =writer.Write(data)
_, err = writer.Write(data)
return err
}

Expand Down
43 changes: 30 additions & 13 deletions cli/internal/cmd.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
package cli

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/unstoppablemango/tdl/pkg/uml"
"google.golang.org/protobuf/proto"
)

func NewFromCmd(create uml.NewConverter) *cobra.Command {
return &cobra.Command{
Use: "from",
Args: cobra.ExactArgs(1),
Use: "from",
RunE: func(cmd *cobra.Command, args []string) error {
opts := uml.ConverterOptions{}
uml.Apply(&opts, uml.WithMimeType(args[0]))
conv := create(opts)
spec, err := conv.From(cmd.Context(), os.Stdin)
fmt.Printf("output:\n%s\n", spec)
return err
spec, err := create(opts).From(cmd.Context(), os.Stdin)
if err != nil {
return err
}

data, err := proto.Marshal(spec)
if err != nil {
return err
}

if _, err = os.Stdout.Write(data); err != nil {
return err
}

return nil
},
}
}

func NewGenCmd(create uml.NewGenerator) *cobra.Command {
return &cobra.Command{
Use: "gen",
Args: cobra.ExactArgs(1),
Use: "gen",
RunE: func(cmd *cobra.Command, args []string) error {
opts := uml.GeneratorOptions{}
uml.Apply(&opts, uml.WithTarget(args[0]))
gen := create(opts)
return gen.Gen(cmd.Context(), &uml.Spec{}, os.Stdout)
data, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}

spec := uml.Spec{}
if err = proto.Unmarshal(data, &spec); err != nil {
return err
}

return create(opts).Gen(cmd.Context(), &spec, os.Stdout)
},
}
}
13 changes: 11 additions & 2 deletions src/RunnerTest/Program.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open System.CommandLine
open System
open System.CommandLine
open System.CommandLine.Builder
open System.CommandLine.Parsing
open System.IO
Expand All @@ -17,7 +18,15 @@ let run (bin: FileInfo) =
let from = CliRunner.from bin.FullName
let gen = CliRunner.gen bin.FullName
let spec = ArbMap.defaults |> TdlArbs.merge |> ArbMap.arbitrary<Spec>
(gen, from) |> RunnerTest.roundTrip |> Prop.forAll spec |> Check.Quick

Console.WriteLine("Executing runner test suite")

[ "Should round-trip", RunnerTest.roundTrip
"Should generate data", RunnerTest.generateData ]
|> List.map (fun (n, t) -> n, t (gen, from))
|> List.map (fun (n, t) -> n, Prop.forAll spec t)
|> List.map Check.Quick
|> ignore

[<EntryPoint>]
let main args =
Expand Down

0 comments on commit 98e1351

Please sign in to comment.