diff --git a/yaml/matrix.go b/yaml/matrix.go index 5cb6e3763..47b6768f1 100644 --- a/yaml/matrix.go +++ b/yaml/matrix.go @@ -29,6 +29,12 @@ func (a Axis) String() string { // ParseMatrix parses the Yaml matrix definition. func ParseMatrix(data []byte) ([]Axis, error) { + + axis, err := parseMatrixList(data) + if err == nil && len(axis) != 0 { + return axis, nil + } + matrix, err := parseMatrix(data) if err != nil { return nil, err @@ -98,3 +104,14 @@ func parseMatrix(raw []byte) (Matrix, error) { err := yaml.Unmarshal(raw, &data) return data.Matrix, err } + +func parseMatrixList(raw []byte) ([]Axis, error) { + data := struct { + Matrix struct { + Include []Axis + } + }{} + + err := yaml.Unmarshal(raw, &data) + return data.Matrix.Include, err +} diff --git a/yaml/matrix_test.go b/yaml/matrix_test.go index aec2ca097..d819cff13 100644 --- a/yaml/matrix_test.go +++ b/yaml/matrix_test.go @@ -30,6 +30,16 @@ func TestMatrix(t *testing.T) { g.Assert(err == nil).IsTrue() g.Assert(axis == nil).IsTrue() }) + + g.It("Should return included axis", func() { + axis, err := ParseMatrixString(fakeMatrixInclude) + g.Assert(err == nil).IsTrue() + g.Assert(len(axis)).Equal(2) + g.Assert(axis[0]["go_version"]).Equal("1.5") + g.Assert(axis[1]["go_version"]).Equal("1.6") + g.Assert(axis[0]["python_version"]).Equal("3.4") + g.Assert(axis[1]["python_version"]).Equal("3.4") + }) }) } @@ -49,3 +59,12 @@ matrix: - 2.6 - 2.8 ` + +var fakeMatrixInclude = ` +matrix: + include: + - go_version: 1.5 + python_version: 3.4 + - go_version: 1.6 + python_version: 3.4 +`