Remove `name` and `aliases`, use `identifier` for everything

This commit is contained in:
Julien Vehent 2015-07-31 13:31:23 -04:00 коммит произвёл Aaron Meihm
Родитель 2ba493c477
Коммит 3019df712a
9 изменённых файлов: 71 добавлений и 109 удалений

Просмотреть файл

@ -31,11 +31,11 @@ func (d *Document) Validate() error {
return nil
}
// Return the names of all tests present in a document.
func (d *Document) GetTestNames() []string {
// Return the identifiers of all tests present in a document.
func (d *Document) GetTestIdentifiers() []string {
ret := make([]string, 0)
for _, x := range d.Tests {
ret = append(ret, x.Name)
ret = append(ret, x.Identifier)
}
return ret
}
@ -54,19 +54,12 @@ func (d *Document) runTests() error {
return nil
}
// Return a pointer to a test instance. Will locate the test whos name matches
// name, or has an alias that matches name.
func (d *Document) getTest(name string) (*test, error) {
// Return a pointer to a test instance of the test whose identifier matches
func (d *Document) getTest(identifier string) (*test, error) {
for i := range d.Tests {
if d.Tests[i].Name == name {
if d.Tests[i].Identifier == identifier {
return &d.Tests[i], nil
}
for _, x := range d.Tests[i].Aliases {
if x == name {
return &d.Tests[i], nil
}
}
}
return nil, fmt.Errorf("unknown test \"%v\"", name)
return nil, fmt.Errorf("unknown test \"%v\"", identifier)
}

Просмотреть файл

@ -26,14 +26,14 @@ func (m *modifier) addMergeTarget(ms *modifierSource) {
}
type modifierSource struct {
Name string `json:"name"`
Select string `json:"select"`
Identifier string `json:"identifier"`
Select string `json:"select"`
criteria modifierData
}
func (m *modifierSource) selectCriteria(t *test) error {
debugPrint("selectCriteria(): modifier selecting criteria from \"%v\"\n", t.Name)
debugPrint("selectCriteria(): modifier selecting criteria from \"%v\"\n", t.Identifier)
// XXX Just support "all" for now, this could change to select specific
// elements of the source criteria slice.
if m.Select != "all" {
@ -43,7 +43,7 @@ func (m *modifierSource) selectCriteria(t *test) error {
if s == nil {
return fmt.Errorf("source has no valid interface")
}
m.criteria.testName = t.Name
m.criteria.testName = t.Identifier
m.criteria.criteria = s.getCriteria()
debugPrint("selectCriteria(): copied %v criteria elements\n", len(m.criteria.criteria))
return nil

Просмотреть файл

@ -44,8 +44,6 @@ func GetResults(d *Document, name string) (TestResult, error) {
return TestResult{}, err
}
ret := TestResult{}
ret.Name = t.Name
ret.Aliases = t.Aliases
ret.Identifier = t.Identifier
if t.err != nil {
ret.Error = fmt.Sprintf("%v", t.err)
@ -77,7 +75,7 @@ func (r *TestResult) SingleLineResults() []string {
rs = "[false]"
}
}
buf := fmt.Sprintf("master %v name:\"%v\" hastrue:%v error:\"%v\"", rs, r.Name, r.HasTrueResults, r.Error)
buf := fmt.Sprintf("master %v name:\"%v\" hastrue:%v error:\"%v\"", rs, r.Identifier, r.HasTrueResults, r.Error)
lns = append(lns, buf)
for _, x := range r.Results {
@ -86,7 +84,7 @@ func (r *TestResult) SingleLineResults() []string {
} else {
rs = "[false]"
}
buf := fmt.Sprintf("sub %v name:\"%v\" identifier:\"%v\"", rs, r.Name, x.Identifier)
buf := fmt.Sprintf("sub %v name:\"%v\" identifier:\"%v\"", rs, r.Identifier, x.Identifier)
lns = append(lns, buf)
}
@ -97,7 +95,7 @@ func (r *TestResult) SingleLineResults() []string {
// suitable for display.
func (r *TestResult) String() string {
lns := make([]string, 0)
lns = append(lns, fmt.Sprintf("result for \"%v\"", r.Name))
lns = append(lns, fmt.Sprintf("result for \"%v\"", r.Identifier))
if r.MasterResult {
lns = append(lns, "\tmaster result: true")
} else {

Просмотреть файл

@ -53,7 +53,7 @@ func Example() {
return
}
// Grab the results for the test, most of the time you would loop
// through the results of GetTestNames() rather then call a result
// through the results of GetTestIdentifiers() rather then call a result
// directly.
result, err := scribe.GetResults(&doc, "example")
if err != nil {

Просмотреть файл

@ -12,19 +12,18 @@ import (
)
type test struct {
Name string `json:"name"`
Identifier string `json:"identifier"`
Aliases []string `json:"aliases"`
Package pkg `json:"package"`
Raw raw `json:"raw"`
Modifier modifier `json:"modifier"`
FileContent filecontent `json:"filecontent"`
FileName filename `json:"filename"`
EVR evrtest `json:"evr"`
Regexp regex `json:"regexp"`
If []string `json:"if"`
Description string `json:"description,omitempty"`
Package pkg `json:"package,omitempty"`
Raw raw `json:"raw,omitempty"`
Modifier modifier `json:"modifier,omitempty"`
FileContent filecontent `json:"filecontent,omitempty"`
FileName filename `json:"filename,omitempty"`
EVR evrtest `json:"evr,omitempty"`
Regexp regex `json:"regexp,omitempty"`
If []string `json:"if,omitempty"`
Expected bool `json:"expectedresult"`
Expected bool `json:"expectedresult,omitempty"`
prepared bool // True if test has been prepared.
evaluated bool // True if test has been evaluated at least once.
@ -72,47 +71,42 @@ type genericEvaluator interface {
}
func (t *test) validate(d *Document) error {
if len(t.Name) == 0 {
if len(t.Identifier) == 0 {
return fmt.Errorf("a test in document has no name")
}
if len(t.Identifier) == 0 {
return fmt.Errorf("%v: no identifier", t.Name)
return fmt.Errorf("%v: no identifier", t.Identifier)
}
si := t.getSourceInterface()
if si == nil {
return fmt.Errorf("%v: no valid source interface", t.Name)
return fmt.Errorf("%v: no valid source interface", t.Identifier)
}
err := si.validate()
if err != nil {
return fmt.Errorf("%v: %v", t.Name, err)
return fmt.Errorf("%v: %v", t.Identifier, err)
}
// If this is a modifier, ensure the modifier sources are valid.
if si.isModifier() {
for _, x := range t.Modifier.Sources {
_, err := d.getTest(x.Name)
_, err := d.getTest(x.Identifier)
if err != nil {
return fmt.Errorf("%v: %v", t.Name, err)
return fmt.Errorf("%v: %v", t.Identifier, err)
}
if x.Select != "all" {
return fmt.Errorf("%v: modifier source must include selector", t.Name)
return fmt.Errorf("%v: modifier source must include selector", t.Identifier)
}
}
}
if t.getEvaluationInterface() == nil {
return fmt.Errorf("%v: no valid evaluation interface", t.Name)
}
for _, x := range t.Aliases {
if len(x) == 0 {
return fmt.Errorf("%v: bad alias within test", t.Name)
}
return fmt.Errorf("%v: no valid evaluation interface", t.Identifier)
}
for _, x := range t.If {
ptr, err := d.getTest(x)
if err != nil {
return fmt.Errorf("%v: %v", t.Name, err)
return fmt.Errorf("%v: %v", t.Identifier, err)
}
if ptr == t {
return fmt.Errorf("%v: test cannot reference itself", t.Name)
return fmt.Errorf("%v: test cannot reference itself", t.Identifier)
}
}
return nil
@ -153,9 +147,9 @@ func (t *test) prepare(d *Document) error {
// If this test is a modifier, prepare all the source tests first.
if len(t.Modifier.Sources) != 0 {
debugPrint("prepare(): readying modifier \"%v\"\n", t.Name)
debugPrint("prepare(): readying modifier \"%v\"\n", t.Identifier)
for i := range t.Modifier.Sources {
nm := t.Modifier.Sources[i].Name
nm := t.Modifier.Sources[i].Identifier
debugPrint("prepare(): preparing modifier source \"%v\"\n", nm)
dt, err := d.getTest(nm)
if err != nil {
@ -200,7 +194,7 @@ func (t *test) runTest(d *Document) error {
return t.err
}
debugPrint("runTest(): running \"%v\"\n", t.Name)
debugPrint("runTest(): running \"%v\"\n", t.Identifier)
t.evaluated = true
// First, see if this test has any dependencies. If so, run those
// before we execute this one.
@ -267,7 +261,7 @@ func (t *test) runTest(d *Document) error {
// validate it and call the handler if required.
if sRuntime.excall != nil {
if t.masterResult != t.Expected {
tr, err := GetResults(d, t.Name)
tr, err := GetResults(d, t.Identifier)
if err != nil {
panic("GetResults() in expected handler")
}

Просмотреть файл

@ -85,7 +85,7 @@ func main() {
os.Exit(1)
}
for _, x := range doc.GetTestNames() {
for _, x := range doc.GetTestIdentifiers() {
tr, err := scribe.GetResults(&doc, x)
if err != nil {
fmt.Fprintf(os.Stderr, "error obtaining results for \"%v\": %v\n", x, err)

Просмотреть файл

@ -5,8 +5,7 @@
"tests": [
{
"name": "filename0",
"identifier": "test0",
"identifier": "filename0",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -16,8 +15,7 @@
},
{
"name": "filename1",
"identifier": "test1",
"identifier": "filename1",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -27,8 +25,7 @@
},
{
"name": "modifier0",
"identifier": "test2",
"identifier": "modifier0",
"expectedresult": false,
"modifier": {
"concat": {
@ -40,8 +37,7 @@
},
{
"name": "modifier1",
"identifier": "test3",
"identifier": "modifier1",
"expectedresult": true,
"modifier": {
"concat": {
@ -49,7 +45,7 @@
},
"sources": [
{
"name": "filename0",
"identifier": "filename0",
"select": "all"
}
]
@ -57,8 +53,7 @@
},
{
"name": "modifier2",
"identifier": "test4",
"identifier": "modifier2",
"expectedresult": true,
"modifier": {
"concat": {
@ -66,7 +61,7 @@
},
"sources": [
{
"name": "filename0",
"identifier": "filename0",
"select": "all"
}
]
@ -78,8 +73,7 @@
},
{
"name": "modifier3",
"identifier": "test5",
"identifier": "modifier3",
"expectedresult": true,
"modifier": {
"concat": {
@ -87,7 +81,7 @@
},
"sources": [
{
"name": "filename0",
"identifier": "filename0",
"select": "all"
}
]
@ -98,8 +92,7 @@
},
{
"name": "modifier4",
"identifier": "test6",
"identifier": "modifier4",
"expectedresult": true,
"modifier": {
"concat": {
@ -107,11 +100,11 @@
},
"sources": [
{
"name": "filename0",
"identifier": "filename0",
"select": "all"
},
{
"name": "filename1",
"identifier": "filename1",
"select": "all"
}
]

Просмотреть файл

@ -5,9 +5,8 @@
"tests": [
{
"name": "simplecontent0",
"aliases": [ "no such file test" ],
"identifier": "test0",
"identifier": "simplecontent0",
"description": "no such file test",
"expectedresult": false,
"filecontent": {
"path": "${root}",
@ -17,8 +16,7 @@
},
{
"name": "simplecontent1",
"identifier": "test1",
"identifier": "simplecontent1",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -28,8 +26,7 @@
},
{
"name": "simplecontent2",
"identifier": "test2",
"identifier": "simplecontent2",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -42,8 +39,7 @@
},
{
"name": "simplecontent3",
"identifier": "test3",
"identifier": "simplecontent3",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -56,8 +52,7 @@
},
{
"name": "filecontent0",
"identifier": "test4",
"identifier": "filecontent0",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -71,8 +66,7 @@
},
{
"name": "filecontent1",
"identifier": "test5",
"identifier": "filecontent1",
"expectedresult": false,
"filecontent": {
"path": "${root}",
@ -83,12 +77,11 @@
"operation": "<",
"value": "0.6"
},
"if": [ "no such file test" ]
"if": [ "simplecontent0" ]
},
{
"name": "filecontent2",
"identifier": "test6",
"identifier": "filecontent2",
"expectedresult": true,
"filecontent": {
"path": "${root}",
@ -103,9 +96,8 @@
},
{
"name": "filecontent3",
"aliases": [ "version is ok" ],
"identifier": "test5",
"identifier": "filecontent3",
"description": "version is ok",
"expectedresult": false,
"filecontent": {
"path": "${root}",
@ -119,8 +111,7 @@
},
{
"name": "anyfile0",
"identifier": "test6",
"identifier": "anyfile0",
"expectedresult": true,
"filecontent": {
"path": "${root}/data",

Просмотреть файл

@ -1,8 +1,7 @@
{
"tests": [
{
"name": "package0",
"identifier": "test0",
"identifier": "package0",
"expectedresult": true,
"package": {
"name": "openssl"
@ -10,8 +9,7 @@
},
{
"name": "package1",
"identifier": "test1",
"identifier": "package1",
"expectedresult": true,
"package": {
"name": "libbind"
@ -23,8 +21,7 @@
},
{
"name": "package2",
"identifier": "test2",
"identifier": "package2",
"expectedresult": false,
"package": {
"name": "grub-common"
@ -36,8 +33,7 @@
},
{
"name": "package3",
"identifier": "test3",
"identifier": "package3",
"expectedresult": false,
"package": {
"name": "grub-common"
@ -49,8 +45,7 @@
},
{
"name": "package4",
"identifier": "test4",
"identifier": "package4",
"expectedresult": false,
"package": {
"name": "grub-common"
@ -62,8 +57,7 @@
},
{
"name": "package5",
"identifier": "test5",
"identifier": "package5",
"expectedresult": false,
"package": {
"name": "grub-common"
@ -76,8 +70,7 @@
},
{
"name": "package6",
"identifier": "test6",
"identifier": "package6",
"expectedresult": false,
"package": {
"name": "openssl"