Skip to content

Commit

Permalink
add testsuite and some mod tests, repro for v0.0.0 bug, caught / fixe…
Browse files Browse the repository at this point in the history
…d to others
  • Loading branch information
verdverm committed May 31, 2020
1 parent 0eb0e59 commit a279f4e
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
/vendor/
/**/vendor/

# Testscript workdirs
/**/.workdir/

# Hof related
/hof-cpu.prof
/hof
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and much much more.

- __single source of truth__: designs mean you can write your idea down in one place, and make all the things from that.
The `hof` tool takes in two directories (designs and generators) and outputs any number of files and directories.
- __data models__: create, view, diff, calculate / migrate, and manage your data models
- __data models__: create, view, diff, calculate / migrate, and manage your data models, like a full service data assistant [should](should)
- __code gen__: generate code, data, and config from your data models and designs
- __poly run__: run polyglot command and scripts seamlessly across runtimes (go, js, py, bash, custom)
- __poly mod__: leverage modules which span languages and technologies
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/mholt/archiver v3.1.1+incompatible // indirect
github.com/naoina/toml v0.1.1
github.com/parnurzeal/gorequest v0.2.16
github.com/rogpeppe/go-internal v1.6.0
github.com/sergi/go-diff v1.1.0
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.6.2 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-internal v1.6.0 h1:IZRgg4sfrDH7nsAD1Y/Nwj+GzIfEwpJSLjCaNC3SbsI=
github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/testscript v1.1.0/go.mod h1:lzMlnW8LS56mcdJoQYkrlzqOoTFCOemzt5LusJ93bDM=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down Expand Up @@ -366,6 +368,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec h1:RlWgLqCMMIYYEVcAR5MDsuHlVkaIPDAF+5Dehzg8L5A=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
Expand Down
29 changes: 29 additions & 0 deletions lib/mod/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package mod_test

import (
"testing"

"github.com/rogpeppe/go-internal/testscript"

"github.com/hofstadter-io/hof/lib/yagu"
)

func TestMod(t *testing.T) {

yagu.Mkdir(".workdir/tests")

testscript.Run(t, testscript.Params{
Dir: "testdata",
WorkdirRoot: ".workdir/tests",
})
}

func TestModBugs(t *testing.T) {

yagu.Mkdir(".workdir/bugs")

testscript.Run(t, testscript.Params{
Dir: "testdata/bugs",
WorkdirRoot: ".workdir/bugs",
})
}
1 change: 1 addition & 0 deletions lib/mod/langs/cue.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cue: {
InitTemplates: {...} | *{
"cue.mod/module.cue": """
module: "{{ .Module }}"
"""
...
}
Expand Down
5 changes: 5 additions & 0 deletions lib/mod/modder/modder_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func (mdr *Modder) WriteVendor() error {

}

// possibly no deps, so lets write an empty sumfile
if mdr.module.SumFile == nil {
mdr.module.SumFile = &sumfile.Sum{}
}

// Write sumfile
out, err := mdr.module.SumFile.Write()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions lib/mod/testdata/bugs/init__module_badfmt_not_caught.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# hof mod init cue blah // this should fail because the module format is incorrect
! exec hof mod init cue blah
stdout '.+'
stderr '.'
15 changes: 15 additions & 0 deletions lib/mod/testdata/bugs/vendor__require_v000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# hof mod vendor - BUG require v0.0.0
exec hof mod vendor

-- cue.mods --
module github.com/test/mod

cue v0.2.0

require (
github.com/hofstadter-io/hof v0.0.0
)
-- cue.mod/module.cue --
module: "github.com/test/mod"
-- dummy_end --

44 changes: 44 additions & 0 deletions lib/mod/testdata/init__arg_errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# hof mod init - no args
! exec hof mod init
stdout 'missing required argument: ''lang'''
stderr 'hof mod init <lang> <module> \[flags\]'


# hof mod init - missing module
! exec hof mod init cue
stdout 'missing required argument: ''module'''
stderr 'hof mod init <lang> <module> \[flags\]'


# hof mod init - unknown lang, missing module
! exec hof mod init blah
stdout 'missing required argument: ''module'''
stderr 'hof mod init <lang> <module> \[flags\]'


# hof mod init - unknown lang, badfmt module
! exec hof mod init blah blah
stdout 'Unknown language "blah".'
! stderr '.'


# hof mod init - unknown lang, goodfmt module
! exec hof mod init blah github.com/test/unknownlang
stdout 'Unknown language "blah".'
! stderr '.'


# hof mod init - backwards args
! exec hof mod init github.com/test/backwards cue
stdout 'Unknown language "github.com/test/backwards".'
! stderr .




# hof mod init - ensure none of these created any files

! exists cue.mods
! exists cue.sums
! exists cue.mod/
! exists cue.mod/module.cue
11 changes: 11 additions & 0 deletions lib/mod/testdata/init__module_initd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# hof mod init - already exists
! exec hof mod init cue github.com/test/overmod
stdout '^cue.mods already exists\n$'
! stderr .

-- cue.mods --
module github.com/test/existsmod

cue v0.2.0
-- dummy-end --

19 changes: 19 additions & 0 deletions lib/mod/testdata/init__new_module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hof mod init cue github.com/test/mod
exec hof mod init cue github.com/test/mod
! stdout .

exists cue.mods
exists cue.mod/module.cue

cmp cue.mods match/cue.mods
cmp cue.mod/module.cue match/cue.mod/module.cue

-- match/cue.mods --
module github.com/test/mod

cue v0.2.0
-- match/cue.mod/module.cue --
module: "github.com/test/mod"
-- dummy_end --


10 changes: 10 additions & 0 deletions lib/mod/testdata/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cli test powered by testscript

This directory contains a number of `txtar` files
which are loaded by the `testscript` library.
These are internal Go libraries from the compiler
extracted into a reusable module.

- https://github.com/rogpeppe/go-internal
- https://pkg.go.dev/github.com/rogpeppe/go-internal

28 changes: 28 additions & 0 deletions lib/mod/testdata/vendor__local_replace_no_require.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# hof mod vendor - local replace no require
exec hof mod vendor



-- cue.mods --
module github.com/test/mod

cue v0.2.0

replace github.com/hofstadter-io/hof => ./simhof

-- cue.mod/module.cue --
module: "github.com/test/mod"
-- dummy_end --


-- simhof/cue.mods --
module github.com/hofstadter-io/hof

cue v0.2.0

-- simhof/cue.mod/module.cue --
module: "github.com/hofstadter-io/hof"


-- dummy_end --

32 changes: 32 additions & 0 deletions lib/mod/testdata/vendor__local_replace_with_require.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# hof mod vendor - local replace
exec hof mod vendor



-- cue.mods --
module github.com/test/mod

cue v0.2.0

require (
github.com/hofstadter-io/hof v0.0.0
)

replace github.com/hofstadter-io/hof => ./simhof

-- cue.mod/module.cue --
module: "github.com/test/mod"
-- dummy_end --


-- simhof/cue.mods --
module github.com/hofstadter-io/hof

cue v0.2.0

-- simhof/cue.mod/module.cue --
module: "github.com/hofstadter-io/hof"


-- dummy_end --

15 changes: 15 additions & 0 deletions lib/mod/testdata/vendor__mod_file_errs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# hof mod vendor - double require
! exec hof mod vendor cue
stdout 'Dependency "github.com/hofstadter-io/hof" required twice in ""'
! stderr .

-- cue.mods --
module github.com/test/2x-req

require (
github.com/hofstadter-io/hof v0.0.0
github.com/hofstadter-io/hof v0.5.4
)

cue v0.2.0
-- dummy-end --
26 changes: 26 additions & 0 deletions lib/mod/testdata/vendor__new_module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# hof mod vendor - new module
exec hof mod init cue github.com/test/mod
! stdout .

exec hof mod vendor
exec hof mod vendor cue

exists cue.mods
cmp cue.mods match/cue.mods

exists cue.sums
cmp cue.sums match/cue.sums

exists cue.mod/module.cue
cmp cue.mod/module.cue match/cue.mod/module.cue

-- match/cue.mods --
module github.com/test/mod

cue v0.2.0
-- match/cue.sums --
-- match/cue.mod/module.cue --
module: "github.com/test/mod"
-- dummy_end --


0 comments on commit a279f4e

Please sign in to comment.