@@ -9,49 +9,60 @@ import (
9
9
"path"
10
10
)
11
11
12
- // print test cases table
13
- func PrintTestCasesTable (inputFiles , outputFiles map [string ]config.IoFile ) {
14
- t := table .NewWriter ()
15
- t .SetOutputMirror (os .Stdout )
16
- t .AppendHeader (table.Row {"#" , "Test Name" , "Input Path" , "Output Path" , "Custon" })
17
- for key , inputFile := range inputFiles {
18
- id := inputFile .GetId ()
19
- testName := inputFile .Name
20
- inputPath := inputFile .Path
21
- outputPath := ""
22
- custom := inputFile .Custom
12
+ type TestCaseIO struct {
13
+ Id int
14
+ Name string
15
+ InputPath string
16
+ OutputPath string
17
+ Custom bool
18
+ }
23
19
24
- outputFile , ok := outputFiles [key ]
25
- if ok {
26
- outputPath = outputFile .Path
20
+ // parse input and output from egor meta to TestCase
21
+ func GetTestCases (egorMeta config.EgorMeta ) []* TestCaseIO {
22
+ testCasesMap := make (map [string ]* TestCaseIO )
23
+ testCases := make ([]* TestCaseIO , 0 )
24
+ for _ , input := range egorMeta .Inputs {
25
+ testCase := & TestCaseIO {
26
+ Id : input .GetId (),
27
+ Name : input .Name ,
28
+ InputPath : input .Path ,
29
+ OutputPath : "" ,
30
+ Custom : input .Custom ,
27
31
}
28
-
29
- t . AppendRow ([] interface {}{ id , testName , inputPath , outputPath , custom } )
32
+ testCasesMap [ input . Name ] = testCase
33
+ testCases = append ( testCases , testCase )
30
34
}
31
- t .SetStyle (table .StyleLight )
32
- t .Render ()
33
- }
34
35
35
- // construct inputs and outputs maps from an egor meta data where keys are test names.
36
- func GetIoFilesMaps (egorMeta config.EgorMeta ) (map [string ]config.IoFile , map [string ]config.IoFile ) {
37
- inputFiles := make (map [string ]config.IoFile )
38
- for _ , inputFile := range egorMeta .Inputs {
39
- inputFiles [inputFile .Name ] = inputFile
36
+ for _ , output := range egorMeta .Outputs {
37
+ if testCase , ok := testCasesMap [output .Name ]; ok {
38
+ testCase .OutputPath = output .Path
39
+ }
40
40
}
41
41
42
- outputFiles := make (map [string ]config.IoFile )
43
- for _ , outputFile := range egorMeta .Outputs {
44
- outputFiles [outputFile .Name ] = outputFile
45
- }
42
+ return testCases
43
+ }
46
44
47
- return inputFiles , outputFiles
45
+ // print test cases table
46
+ func PrintTestCasesTable (testCases []* TestCaseIO ) {
47
+ t := table .NewWriter ()
48
+ t .SetOutputMirror (os .Stdout )
49
+ t .AppendHeader (table.Row {"#" , "Test Name" , "Input Path" , "Output Path" , "Custon" })
50
+ for _ , testCase := range testCases {
51
+ t .AppendRow ([]interface {}{
52
+ testCase .Id ,
53
+ testCase .Name ,
54
+ testCase .InputPath ,
55
+ testCase .OutputPath ,
56
+ testCase .Custom ,
57
+ })
58
+ }
59
+ t .SetStyle (table .StyleLight )
60
+ t .Render ()
48
61
}
49
62
50
63
// print task test cases
51
- func PrintTestCases (egorMeta config.EgorMeta ) error {
52
- inputFiles , outputFiles := GetIoFilesMaps (egorMeta )
53
- PrintTestCasesTable (inputFiles , outputFiles )
54
- return nil
64
+ func PrintTestCases (egorMeta config.EgorMeta ) {
65
+ PrintTestCasesTable (GetTestCases (egorMeta ))
55
66
}
56
67
57
68
// list test cases information command action
@@ -79,11 +90,8 @@ func ShowCasesAction(context *cli.Context) error {
79
90
color .Green ("Listing %d testcase(s)..." , metaData .CountTestCases ())
80
91
color .Green ("" )
81
92
82
- err = PrintTestCases (metaData )
83
- if err != nil {
84
- color .Red ("Error while printing test cases" )
85
- return err
86
- }
93
+ PrintTestCases (metaData )
94
+
87
95
return nil
88
96
}
89
97
@@ -92,7 +100,7 @@ func ShowCasesAction(context *cli.Context) error {
92
100
// and prints it as an array into the consol.
93
101
var ShowCasesCommand = cli.Command {
94
102
Name : "showcases" ,
95
- Aliases : []string {"listcases " },
103
+ Aliases : []string {"sc " },
96
104
Usage : "list information about test cases" ,
97
105
UsageText : "list meta data about of the tests cases in the current task" ,
98
106
Action : ShowCasesAction ,
0 commit comments