示例#1
0
func TestParser(t *testing.T) {
	var (
		parser   *Parser
		packages = []*contract.Package{
			&contract.Package{Active: true, Output: "Active!", Result: contract.NewPackageResult("asdf")},
			&contract.Package{Active: false, Output: "Inactive!", Result: contract.NewPackageResult("qwer")},
		}
	)

	Convey("Subject: Parser parses test output for active packages", t, func() {
		parser = NewParser(fakeParserImplementation)

		Convey("When given a collection of packages", func() {
			parser.Parse(packages)

			Convey("The parser uses its internal parsing mechanism to parse the output of only the active packages", func() {
				So(packages[0].Result.Outcome, ShouldEqual, packages[0].Output)
			})

			Convey("The parser should mark inactive packages as ignored", func() {
				So(packages[1].Result.Outcome, ShouldEqual, contract.Ignored)
			})
		})
	})
}
示例#2
0
func TestParser(t *testing.T) {

	Convey("Subject: Parser parses test output for active packages", t, func() {
		packages := []*contract.Package{
			&contract.Package{Ignored: false, Output: "Active", Result: contract.NewPackageResult("asdf")},
			&contract.Package{Ignored: true, Output: "Inactive", Result: contract.NewPackageResult("qwer")},
		}
		parser := NewParser(fakeParserImplementation)

		Convey("When given a collection of packages", func() {
			parser.Parse(packages)

			Convey("The parser uses its internal parsing mechanism to parse the output of only the active packages", func() {
				So(packages[0].Result.Outcome, ShouldEqual, packages[0].Output)
			})

			Convey("The parser should mark inactive packages as ignored", func() {
				So(packages[1].Result.Outcome, ShouldEqual, contract.Ignored)
			})
		})

		Convey("When a package could not be tested (maybe it was deleted between scanning and execution?)", func() {
			packages[0].Output = ""
			packages[0].Error = errors.New("Directory does not exist")

			parser.Parse(packages)

			Convey("The package result should not be parsed and the outcome should actually resemble the problem", func() {
				So(packages[0].Result.Outcome, ShouldEqual, contract.TestRunAbortedUnexpectedly)
			})
		})
	})
}
示例#3
0
func (self *Watcher) WatchedFolders() []*contract.Package {
	i, watched := 0, make([]*contract.Package, len(self.watched))
	log.Println("Number of watched folders:", len(self.watched))
	for _, item := range self.watched {
		watched[i] = &contract.Package{
			Active: item.Active,
			Path:   item.Path,
			Name:   item.Name,
			Result: contract.NewPackageResult(item.Name),
		}
		i++
	}
	return watched
}
示例#4
0
func (self *watcherFixture) pointToExistingRootWithNestedFolders() (actual, expected interface{}) {
	self.files.Create(goProject, 1, time.Now())
	self.files.Create(goProject+normalize("/sub"), 2, time.Now())
	self.files.Create(goProject+normalize("/sub2"), 3, time.Now())
	self.files.Create(goProject+normalize("/sub/subsub"), 4, time.Now())

	self.watcher.Adjust(goProject)

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{
			Active: true,
			Path:   goProject,
			Name:   goPackagePrefix,
			Result: contract.NewPackageResult(goPackagePrefix),
		},
		&contract.Package{
			Active: true,
			Path:   goProject + normalize("/sub"),
			Name:   goPackagePrefix + normalize("/sub"),
			Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub")),
		},
		&contract.Package{
			Active: true,
			Path:   goProject + normalize("/sub/subsub"),
			Name:   goPackagePrefix + normalize("/sub/subsub"),
			Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub/subsub")),
		},
		&contract.Package{
			Active: true,
			Path:   goProject + normalize("/sub2"),
			Name:   goPackagePrefix + normalize("/sub2"),
			Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub2")),
		},
	}
	return
}
示例#5
0
func (self *watcherFixture) reinstateIgnoredFolder() (actual, expected interface{}) {
	self.files.Create(goProject, 1, time.Now())
	self.files.Create(goProject+"/sub", 2, time.Now())
	self.watcher.Adjust(goProject)
	self.watcher.Ignore(goPackagePrefix + "/sub")

	self.watcher.Reinstate(goProject + "/sub")

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{Active: true, Path: goProject, Name: goPackagePrefix, Result: contract.NewPackageResult(goPackagePrefix)},
		&contract.Package{Active: true, Path: goProject + "/sub", Name: goPackagePrefix + "/sub", Result: contract.NewPackageResult(goPackagePrefix + "/sub")},
	}
	return
}
示例#6
0
func (self *watcherFixture) pointToExistingRoot(folder string) (actual, expected interface{}) {
	self.files.Create(folder, 1, time.Now())

	self.watcher.Adjust(folder)

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{
			Active: true,
			Path:   goProject,
			Name:   goPackagePrefix,
			Result: contract.NewPackageResult(goPackagePrefix),
		},
	}
	return
}
示例#7
0
func (self *watcherFixture) reinstateIrrelevantFolder() (actual, expected interface{}) {
	self.files.Create(goProject, 1, time.Now())
	self.files.Create(normalize("/irrelevant"), 2, time.Now())
	self.watcher.Adjust(goProject)

	self.watcher.Reinstate(normalize("/irrelevant"))

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{
			Active: true,
			Path:   goProject,
			Name:   goPackagePrefix,
			Result: contract.NewPackageResult(goPackagePrefix),
		},
	}
	return
}
示例#8
0
func (self *watcherFixture) reinstateIgnoredFolders() (actual, expected interface{}) {
	self.files.Create(goProject, 1, time.Now())
	self.files.Create(goProject+normalize("/sub"), 2, time.Now())
	self.files.Create(goProject+normalize("/sub2"), 3, time.Now())
	self.files.Create(goProject+normalize("/sub3"), 4, time.Now())
	self.watcher.Adjust(goProject)
	self.watcher.Ignore(goPackagePrefix + normalize("/sub;") + goPackagePrefix + normalize("/sub2;") + goPackagePrefix + normalize("/sub3"))

	self.watcher.Reinstate(goProject + normalize("/sub;") + goPackagePrefix + normalize("/sub3"))

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{Active: true, Path: goProject, Name: goPackagePrefix, Result: contract.NewPackageResult(goPackagePrefix)},
		&contract.Package{Active: true, Path: goProject + normalize("/sub"), Name: goPackagePrefix + normalize("/sub"), Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub"))},
		&contract.Package{Active: false, Path: goProject + normalize("/sub2"), Name: goPackagePrefix + normalize("/sub2"), Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub2"))},
		&contract.Package{Active: true, Path: goProject + normalize("/sub3"), Name: goPackagePrefix + normalize("/sub3"), Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub3"))},
	}
	return
}
示例#9
0
func (self *Watcher) WatchedFolders() []*contract.Package {
	log.Println("Number of watched folders:", len(self.watched))

	paths := []string{}
	for _, item := range self.watched {
		paths = append(paths, item.Path)
	}
	sort.Strings(paths)

	watched := make([]*contract.Package, len(self.watched))
	for i, path := range paths {
		item := self.watched[path]
		watched[i] = &contract.Package{
			Active: item.Active,
			Path:   item.Path,
			Name:   item.Name,
			Result: contract.NewPackageResult(item.Name),
		}
	}
	return watched
}
示例#10
0
func (self *watcherFixture) ignoreImaginaryFolder() (actual, expected interface{}) {
	self.files.Create(goProject, 1, time.Now())
	self.watcher.Adjust(goProject)

	self.watcher.Ignore("/not/there")

	actual = self.watched()
	expected = []*contract.Package{&contract.Package{Active: true, Path: goProject, Name: goPackagePrefix, Result: contract.NewPackageResult(goPackagePrefix)}}
	return
}
示例#11
0
func (self *watcherFixture) ignoreWatchedFolders() (actual, expected interface{}) {
	self.watcher.Creation(goProject + "/sub2")
	self.watcher.Creation(goProject + "/sub3")
	self.watcher.Creation(goProject + "/sub4")

	self.watcher.Ignore(goPackagePrefix + "/sub2;" + goPackagePrefix + "/sub4")

	actual = self.watched()
	expected = []*contract.Package{
		&contract.Package{Active: false, Path: goProject + "/sub2", Name: goPackagePrefix + "/sub2", Result: contract.NewPackageResult(goPackagePrefix + "/sub2")},
		&contract.Package{Active: true, Path: goProject + "/sub3", Name: goPackagePrefix + "/sub3", Result: contract.NewPackageResult(goPackagePrefix + "/sub3")},
		&contract.Package{Active: false, Path: goProject + "/sub4", Name: goPackagePrefix + "/sub4", Result: contract.NewPackageResult(goPackagePrefix + "/sub4")},
	}
	return
}
示例#12
0
func (self *watcherFixture) receiveNotificationOfDeletedFolder() (actual, expected interface{}) {
	self.watcher.Creation(goProject + "/sub2")
	self.watcher.Creation(goProject + "/sub")

	self.watcher.Deletion(goProject + "/sub")

	actual = self.watched()
	expected = []*contract.Package{&contract.Package{Active: true, Path: goProject + "/sub2", Name: goPackagePrefix + "/sub2", Result: contract.NewPackageResult(goPackagePrefix + "/sub2")}}
	return
}
示例#13
0
func (self *watcherFixture) ignoreWatchedFolder() (actual, expected interface{}) {
	self.watcher.Creation(goProject + normalize("/sub2"))

	self.watcher.Ignore(goPackagePrefix + normalize("/sub2"))

	actual = self.watched()
	expected = []*contract.Package{&contract.Package{Active: false, Path: goProject + normalize("/sub2"), Name: goPackagePrefix + normalize("/sub2"), Result: contract.NewPackageResult(goPackagePrefix + normalize("/sub2"))}}
	return
}