Skip to content

Commit

Permalink
Merge pull request #66 from hofstadter-io/structural-work
Browse files Browse the repository at this point in the history
Prepare for Data Model work
  • Loading branch information
verdverm committed Sep 17, 2020
2 parents 079c913 + 69d343f commit d584469
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions .hof/shadow/Cli/cmd/hof/cmd/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var DatamodelCmd = &cobra.Command{

Aliases: []string{
"dmod",
"dm",
},

Short: "create, view, diff, calculate / migrate, and manage your data models",
Expand Down
1 change: 1 addition & 0 deletions cmd/hof/cmd/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var DatamodelCmd = &cobra.Command{

Aliases: []string{
"dmod",
"dm",
},

Short: "create, view, diff, calculate / migrate, and manage your data models",
Expand Down
2 changes: 1 addition & 1 deletion design/cli/cmds/datamodel.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
TBD: "α"
Name: "datamodel"
Usage: "datamodel"
Aliases: ["dmod"]
Aliases: ["dmod", "dm"]
Short: "create, view, diff, calculate / migrate, and manage your data models"
Long: Short

Expand Down
3 changes: 2 additions & 1 deletion lib/cuetils/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func GetByAttrKeys(val cue.Value, attr string, all, any []string) ([]KeyVal, err
hasattr := false
for _, A := range attrs {
// does it have an "@<attr>(...)"
if A.Name() == attr {
if A.Name() == attr {

vals := A.Vals()

// must match all
Expand Down
2 changes: 2 additions & 0 deletions lib/structural/testdata/000_shared_examples.cue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package testdata

@examples(shared)
#SharedExamples: {

Expand Down
25 changes: 21 additions & 4 deletions lib/structural/testdata/merge_cases.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ package testdata
@cases(merge)
#MergeCases: {
@group(simple)
simple: {
edge: {
t_0001: {
args: {
orig: #SharedExamples.A
merge: {a: "a", N: {x: "x"}}
orig: {a: "a"}
merge: {}
}
ex: {a: "a", b: "b", N: {x: "x", y: "y"}}
ex: {a: "a"}
}
t_0002: {
args: {
orig: {}
merge: {a: "a"}
}
ex: {a: "a"}
}
}
//@group(simple)
//simple: {
//t_0002: {
//args: {
//orig: #SharedExamples.A
//merge: {a: "a", N: {x: "x"}}
//}
//ex: {a: "a", b: "b", N: {x: "x", y: "y"}}
//}
//}
}
4 changes: 2 additions & 2 deletions lib/test/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func RunTestFromArgsFlags(args []string, cmdflags flags.TestFlagpole) (error) {
}

// Get test suites from top level
suites, err := getValueTestSuites(crt.CueValue, "suites", cmdflags.Suite)
suites, err := getValueTestSuites(crt.CueValue, cmdflags.Suite)
if err != nil {
return err
}

// find tests in suites
for s, suite := range suites {
ts, err := getValueTestSuiteTesters(suite.Value, suite.Name, cmdflags.Tester)
ts, err := getValueTestSuiteTesters(suite.Value, cmdflags.Tester)
if err != nil {
return err
}
Expand Down
11 changes: 9 additions & 2 deletions lib/test/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func RunSuites(suites []Suite, verbose int) (TS Stats, err error) {

// loop over tests
for s, S := range suites {
// Short circuit for empty suites
if len(S.Tests) == 0 {
continue
}

// set start time
S.Stats.Start = time.Now()

Expand All @@ -25,8 +30,10 @@ func RunSuites(suites []Suite, verbose int) (TS Stats, err error) {
S.Errors = append(S.Errors, err)
}

// set the element again because of Go copy
// update total time
S.Stats.Time += T.Stats.Time

// set the element because of Go value copy in the loop header
S.Tests[t] = T
}

Expand All @@ -48,7 +55,7 @@ func RunTest(T *Tester, verbose int) (err error) {
// stats work
T.Stats.Start = time.Now()

// TODO< find and possibly skip
// TODO find and possibly skip
skip := T.Value.Lookup("skip")
if skip.Exists() {
doskip, err := skip.Bool()
Expand Down
6 changes: 3 additions & 3 deletions lib/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Suite struct {
Errors []error
}

func getValueTestSuites(val cue.Value, name string, labels []string) ([]Suite, error) {
vals, err := cuetils.GetByAttrKeys(val, "test", []string{"suite"}, labels)
func getValueTestSuites(val cue.Value, labels []string) ([]Suite, error) {
vals, err := cuetils.GetByAttrKeys(val, "test", append(labels, "suite"), nil)
suites := []Suite{}
for _, v := range vals {
suites = append(suites, Suite{Name: v.Key, Value: v.Val})
Expand Down Expand Up @@ -59,7 +59,7 @@ type Tester struct {
Errors []error
}

func getValueTestSuiteTesters(val cue.Value, name string, labels []string) ([]Tester, error) {
func getValueTestSuiteTesters(val cue.Value, labels []string) ([]Tester, error) {
vals, err := cuetils.GetByAttrKeys(val, "test", labels, []string{})
testers := []Tester{}
for _, v := range vals {
Expand Down
9 changes: 0 additions & 9 deletions test.cue
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ import "strings"
...
}

#GoExecTest: #GoBaseTest & {
command: string | *"go test -cover ./"
...
}

//
////// Actual test configuration
//
Expand Down Expand Up @@ -81,12 +76,10 @@ hls: {

script: #GoBashTest @test(bash,test,script)
script: {
skip: true
dir: "script"
}
scriptC: #GoBashCover @test(bash,cover,script)
scriptC: {
skip: true
dir: "script"
}
}
Expand All @@ -105,12 +98,10 @@ lib: {

st: #GoBashTest @test(bash,test,st)
st: {
skip: true
dir: "lib/structural"
}
stC: #GoBashCover @test(bash,cover,st)
stC: {
skip: true
dir: "lib/structural"
}

Expand Down

0 comments on commit d584469

Please sign in to comment.