Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 9f9f42b + 0284245 commit 2be30fe0e11cc6b4cbbdd86ded46be57aa526505 @AlekSi committed Mar 18, 2013
Showing with 960 additions and 291 deletions.
  1. +1 −2 .gitignore
  2. +5 −1 .travis.yml
  3. +16 −2 CHANGELOG
  4. +3 −3 CONTRIBUTING.md
  5. +21 −17 Makefile
  6. +2 −1 README.md
  7. +19 −0 build.bat
  8. +115 −0 integration_test/hook_for_test.go
  9. +119 −0 integration_test/local_test.go
  10. +77 −0 integration_test/remote_test.go
  11. +56 −4 nut.go
  12. +2 −1 nut.json
  13. +102 −86 nut/base.go
  14. +15 −6 nut/check.go
  15. +20 −13 nut/generate.go
  16. +114 −37 nut/get.go
  17. +42 −8 nut/get_test.go
  18. +29 −11 nut/install.go
  19. +12 −8 nut/main.go
  20. +17 −6 nut/pack.go
  21. +19 −16 nut/publish.go
  22. +8 −5 nut/unpack.go
  23. +53 −28 nut_test.go
  24. +31 −3 spec.go
  25. +41 −22 spec_test.go
  26. +2 −2 version.go
  27. +19 −9 version_test.go
View
@@ -1,3 +1,2 @@
-gonut
+*.exe
*.nut
-gopath/
View
@@ -1,3 +1,7 @@
language: go
-before_install: sudo apt-get -qq install bzr
+before_install:
+ - sudo apt-get -qq install bzr
+ - mkdir -p $GOPATH/src/github.com/AlekSi
+ - cp -R `pwd` $GOPATH/src/github.com/AlekSi
install: make prepare
+script: make -C $GOPATH/src/github.com/AlekSi/nut
View
@@ -1,7 +1,21 @@
+2013-03-18: 0.3.0
+ + Add vendors.
+ * `nut install` now installs into <prefix>/<vendor>/<name> (omits version component).
+ + `nut get` now downloads and installs all dependencies (recursive).
+ + `nut get` now may be used without arguments.
+ * `nut pack` now includes files for all OSes.
+ + New API for Spec: ReadFile().
+ + New API for Nut: ReadFrom(), FilePath(), ImportPath().
+ + New API for NutFile: ReadFile().
+ * Fix bug with `nut get` and www.-prefixed hosts.
+ * Fix some issues on Windows.
+ * Fix -h and extra arguments handling.
+ - Disallow package names ending with "_".
+
2012-12-16: 0.2.0
+ Add homepage to spec.
- + Read -v from .nut.json.
- * Write .nut.json in some cases.
+ + Read -v from ~/.nut.json.
+ * Write ~/.nut.json in some cases.
* Do not panic in some cases.
* Fix bug in `nut check` for spec file in other directory.
- Remove confusing -server option (was useful only for development).
View
@@ -1,7 +1,7 @@
Filling issues and contributing to nut tool
===========================================
-First of all, thank you for your interest in making packaging better! There are number of ways you can help:
+First of all, thank you for your interest in making Go ecosystem better! There are number of ways you can help:
* reporting bugs;
* proposing features;
@@ -13,7 +13,7 @@ The following sections describes those scenarios. Golden rule: communicate first
Reporting bugs
--------------
-1. Make sure bug is reproducible with latest released version: `go get -u github.com/AlekSi/nut/nut`.
+1. Make sure bug is reproducible with latest released version: `go get -u github.com/AlekSi/nut/...`.
2. Search for [existing bug report](https://github.com/AlekSi/nut/issues).
3. Create a new issue if needed. Please do not assign any label.
4. Include output of:
@@ -34,7 +34,7 @@ Contributing changes
1. Read all previous sections first.
2. Nut tool uses [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/). Make sure you are starting with branch `develop` for new feature and `master` for bug fix.
3. You can make small changes right in the web interface. Spot a typo? Fix it! :)
-4. For bigger changes make a fork on GitHub and clone it into `$GOPATH/src/github.com/AlekSi/nut`.
+4. For bigger changes setup a separate workspace a.k.a. GOPATH (strictly required for integration tests), make a fork on GitHub and clone it into `$GOPATH/src/github.com/AlekSi/nut`.
5. Run `make prepare` to install remote packages and `make` to run unit and integration tests.
6. Use `git flow feature start` or `git flow hotfix start` to create a branch.
7. Make your changes. Run and update tests. Do not change version.
View
@@ -1,27 +1,31 @@
-all: test
+GO?=go
+
+all: short
prepare:
- go get -u launchpad.net/gocheck
- go get -u github.com/AlekSi/test_nut1
+ $(GO) env
+ $(GO) get -u launchpad.net/gocheck
+ $(GO) get -u github.com/AlekSi/test_nut1
+ -$(GO) get -u github.com/AlekSi/test_nut2
+ -$(GO) get -u github.com/AlekSi/test_nut3
# format, vet, build
fvb:
gofmt -e -s -w .
- go tool vet .
- go build -v -o gonut ./nut
+ $(GO) tool vet .
+ $(GO) install github.com/AlekSi/nut
+ $(GO) build -o gonut.exe github.com/AlekSi/nut/nut
+ -errcheck github.com/AlekSi/nut
+ -errcheck github.com/AlekSi/nut/nut
+ -errcheck github.com/AlekSi/nut/integration_test
test: fvb
- cd ../test_nut1 && rm -f *.nut
- cd ../test_nut1 && ../nut/gonut generate -v
- cd ../test_nut1 && ../nut/gonut check -v
- cd ../test_nut1 && ../nut/gonut pack -v
- cd ../test_nut1 && ../nut/gonut check -v test_nut1-0.0.1.nut
- cd ../test_nut1 && ../nut/gonut unpack -v test_nut1-0.0.1.nut
-
- go test -v ./...
+ cd ../test_nut1 && ../nut/gonut.exe pack
+ $(GO) test -v github.com/AlekSi/nut -gocheck.v
+ $(GO) test -v github.com/AlekSi/nut/nut -gocheck.v
- cd ../test_nut1 && ../nut/gonut install -v test_nut1-0.0.1.nut
+short: test
+ $(GO) test -v -short github.com/AlekSi/nut/integration_test -gocheck.v
-test_server: test
- cd ../test_nut1 && GONUTS_SERVER=localhost:8080 ../nut/gonut publish -v test_nut1-0.0.1.nut
- cd ../test_nut1 && GONUTS_SERVER=localhost:8080 ../nut/gonut get -v test_nut1/0.0.1
+full: test
+ GONUTS_IO_SERVER=http://localhost:8080 $(GO) test -v github.com/AlekSi/nut/integration_test -gocheck.v
View
@@ -13,5 +13,6 @@ Nut is a tool to manage versioned [Go](http://golang.org) source code packages,
Install it with `go get`:
- go get -u github.com/AlekSi/nut/nut
+ go get -u github.com/AlekSi/nut/...
+ touch ~/.nut.json
nut help
View
@@ -0,0 +1,19 @@
+go install github.com/AlekSi/nut
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
+
+go build -o gonut.exe github.com/AlekSi/nut/nut
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
+
+@pushd ..\test_nut1
+..\nut\gonut.exe pack
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
+@popd
+
+go test -v github.com/AlekSi/nut -gocheck.v
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
+
+go test -v github.com/AlekSi/nut/nut -gocheck.v
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
+
+go test -v -short github.com/AlekSi/nut/integration_test -gocheck.v
+@if ERRORLEVEL 1 exit /B %ERRORLEVEL%
@@ -0,0 +1,115 @@
+package integration_test
+
+import (
+ "bytes"
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "syscall"
+ "testing"
+
+ . "launchpad.net/gocheck"
+)
+
+// Global gocheck hook.
+func TestIntegration(t *testing.T) { TestingT(t) }
+
+var (
+ TestNut1 = "../../test_nut1"
+ TestNut2 = "../../test_nut2"
+ TestNut3 = "../../test_nut3"
+ Wd string
+ nutBin string
+)
+
+func init() {
+ var err error
+ Wd, err = os.Getwd()
+ if err != nil {
+ panic(err)
+ }
+
+ nutBin = filepath.Join(Wd, "..", "gonut.exe")
+ TestNut1 = filepath.Join(Wd, TestNut1)
+ TestNut2 = filepath.Join(Wd, TestNut2)
+ TestNut3 = filepath.Join(Wd, TestNut3)
+}
+
+func setupTest(c *C) {
+ for _, dir := range []string{TestNut1, TestNut2, TestNut3} {
+ runCommand(c, dir, "git", "reset --hard origin/master")
+ runCommand(c, dir, "git", "clean -xdf")
+ }
+
+ oa := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
+ for _, dir := range []string{
+ filepath.Join(Wd, "../../../../gonuts.io/"),
+ filepath.Join(Wd, "../../../../localhost/"),
+ filepath.Join(Wd, "../../../../../pkg/"+oa+"/gonuts.io/"),
+ filepath.Join(Wd, "../../../../../pkg/"+oa+"/localhost/"),
+ filepath.Join(Wd, "../../../../../bin/"),
+ filepath.Join(Wd, "../../../../../nut/"),
+ } {
+ // c.Logf("Removing %s", dir)
+ c.Assert(os.RemoveAll(dir), IsNil)
+ }
+}
+
+func runCommand(c *C, dir, command string, args string, exitCode ...int) (stdout, stderr string) {
+ var expectedCode int
+ switch len(exitCode) {
+ case 0:
+ case 1:
+ expectedCode = exitCode[0]
+ default:
+ c.Fatal("Invalid invocation of runCommand")
+ }
+
+ o, e := bytes.Buffer{}, bytes.Buffer{}
+ cmd := exec.Command(command, strings.Split(args, " ")...)
+ cmd.Dir = dir
+ cmd.Stdout, cmd.Stderr = &o, &e
+ err := cmd.Run()
+ stdout, stderr = strings.TrimSpace(o.String()), strings.TrimSpace(e.String())
+ c.Logf("%s: %s %s", dir, command, args)
+ if stdout != "" {
+ c.Logf("stdout: %s", stdout)
+ }
+ if stderr != "" {
+ c.Logf("stderr: %s", stderr)
+ }
+
+ if err == nil {
+ if expectedCode == 0 {
+ return
+ } else {
+ c.Fatalf("Expected exit code %d, got 0.", expectedCode)
+ }
+ }
+
+ ee, ok := err.(*exec.ExitError)
+ if !ok {
+ c.Fatal(err)
+ }
+ actualCode := ee.Sys().(syscall.WaitStatus).ExitStatus() // why it's so hard?..
+ if expectedCode != actualCode {
+ c.Fatalf("Expected exit code %d, got %d.", expectedCode, actualCode)
+ }
+
+ return
+}
+
+func runNut(c *C, dir string, args string, exitCode ...int) (stdout, stderr string) {
+ return runCommand(c, dir, nutBin, args, exitCode...)
+}
+
+func runGo(c *C, dir string, args string, exitCode ...int) (stdout, stderr string) {
+ return runCommand(c, dir, "go", args, exitCode...)
+}
+
+func gitNoDiff(c *C, dir string) {
+ runCommand(c, dir, "git", "diff --exit-code")
+}
@@ -0,0 +1,119 @@
+package integration_test
+
+import (
+ "os"
+ "runtime"
+ "strings"
+
+ . "launchpad.net/gocheck"
+)
+
+type L struct{}
+
+var _ = Suite(&L{})
+
+func (*L) SetUpTest(c *C) {
+ setupTest(c)
+}
+
+func (l *L) TearDownTest(c *C) {
+ l.SetUpTest(c)
+}
+
+func (*L) TestGenerateCheck(c *C) {
+ _, stderr := runNut(c, TestNut1, "generate -v")
+ c.Check(stderr, Equals, "nut.json updated.")
+ gitNoDiff(c, TestNut1)
+
+ _, stderr = runNut(c, TestNut1, "check -v")
+ c.Check(stderr, Equals, "nut.json looks good.")
+ gitNoDiff(c, TestNut1)
+
+ c.Check(os.Remove(TestNut2+"/nut.json"), IsNil)
+ _, stderr = runNut(c, TestNut2, "generate -v")
+ expected := `
+nut.json generated.
+
+Now you should edit nut.json to fix following errors:
+ Version "0.0.0" is invalid.
+ Vendor should contain only lower word characters (match "^[0-9a-z][0-9a-z_-]*$").
+ "Crazy Nutter" is not a real person.
+
+After that run 'nut check' to check spec again.`[1:]
+ c.Check(stderr, Equals, expected)
+ _, err := os.Stat(TestNut2 + "/nut.json")
+ c.Check(err, IsNil)
+
+ _, stderr = runNut(c, TestNut2, "check -v", 1)
+ expected = `
+Found errors in nut.json:
+ Version "0.0.0" is invalid.
+ Vendor should contain only lower word characters (match "^[0-9a-z][0-9a-z_-]*$").
+ "Crazy Nutter" is not a real person.`[1:]
+ c.Check(stderr, Equals, expected)
+
+ c.Check(os.Remove(TestNut3+"/test_nut3.go"), IsNil)
+ _, stderr = runNut(c, TestNut3, "generate -v", 1)
+ c.Check(stderr, Equals, "no Go source files in .")
+
+ _, stderr = runNut(c, TestNut3, "check -v", 1)
+ c.Check(strings.HasPrefix(stderr, "no Go source files in ."), Equals, true)
+}
+
+func (*L) TestPackCheckUnpack(c *C) {
+ _, stderr := runNut(c, TestNut1, "pack -v")
+ c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut created."), Equals, true)
+ gitNoDiff(c, TestNut1)
+
+ _, stderr = runNut(c, TestNut1, "check -v test_nut1-0.0.1.nut")
+ c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut looks good."), Equals, true)
+ gitNoDiff(c, TestNut1)
+
+ c.Check(os.Remove(TestNut1+"/test_nut1.go"), IsNil)
+ _, stderr = runNut(c, TestNut1, "unpack -v test_nut1-0.0.1.nut")
+ c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut unpacked."), Equals, true)
+ gitNoDiff(c, TestNut1)
+
+ c.Check(os.Remove(TestNut2+"/nut.json"), IsNil)
+ runNut(c, TestNut2, "generate -v")
+ _, stderr = runNut(c, TestNut2, "pack -v", 1)
+ c.Check(strings.HasPrefix(stderr, "Found errors:"), Equals, true)
+ _, stderr = runNut(c, TestNut2, "pack -nc -v")
+ c.Check(strings.HasSuffix(stderr, "test_nut2-0.0.0.nut created."), Equals, true)
+
+ _, stderr = runNut(c, TestNut2, "check -v test_nut2-0.0.0.nut", 1)
+ c.Check(strings.HasPrefix(stderr, "Found errors in test_nut2-0.0.0.nut:"), Equals, true)
+
+ c.Check(os.Remove(TestNut3+"/README"), IsNil)
+ _, stderr = runNut(c, TestNut3, "pack -nc -v", 1)
+
+ if runtime.GOOS == "windows" {
+ c.Check(strings.HasSuffix(stderr, "README: The system cannot find the file specified."), Equals, true)
+ } else {
+ c.Check(strings.HasSuffix(stderr, "README: no such file or directory"), Equals, true)
+ }
+}
+
+func (*L) TestPackInstall(c *C) {
+ packages := make(map[string]bool)
+ stdout, _ := runGo(c, TestNut1, "list all")
+ for _, p := range strings.Split(stdout, "\n") {
+ packages[p] = true
+ }
+
+ _, stderr := runNut(c, TestNut1, "pack -v")
+ c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut created."), Equals, true)
+ gitNoDiff(c, TestNut1)
+
+ _, stderr = runNut(c, TestNut1, "install -v test_nut1-0.0.1.nut")
+ c.Check(strings.HasSuffix(stderr, "localhost/debug/test_nut1"), Equals, true)
+
+ stdout, _ = runGo(c, TestNut1, "list all")
+ var newPackages []string
+ for _, p := range strings.Split(stdout, "\n") {
+ if !packages[p] {
+ newPackages = append(newPackages, p)
+ }
+ }
+ c.Check(newPackages, DeepEquals, []string{"localhost/debug/test_nut1"})
+}
Oops, something went wrong.

0 comments on commit 2be30fe

Please sign in to comment.