11package ch .njol .skript .test .platform ;
22
33import ch .njol .skript .test .utils .TestResults ;
4- import ch .njol .util .NonNullPair ;
54import com .google .common .collect .Sets ;
65import com .google .gson .Gson ;
76import com .google .gson .GsonBuilder ;
87import com .google .gson .JsonSyntaxException ;
98import org .apache .commons .lang .StringUtils ;
109
1110import java .io .IOException ;
12- import java .nio .charset .StandardCharsets ;
1311import java .nio .file .Files ;
1412import java .nio .file .Path ;
1513import java .nio .file .Paths ;
16- import java .util .ArrayList ;
17- import java .util .Arrays ;
18- import java .util .Collections ;
19- import java .util .Comparator ;
20- import java .util .HashMap ;
21- import java .util .HashSet ;
22- import java .util .List ;
23- import java .util .Locale ;
24- import java .util .Map ;
25- import java .util .Set ;
14+ import java .util .*;
2615import java .util .stream .Collectors ;
2716
2817/**
@@ -36,13 +25,16 @@ public static void main(String... args) throws IOException, InterruptedException
3625 Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
3726
3827 Path runnerRoot = Paths .get (args [0 ]);
39- assert runnerRoot != null ;
4028 Path testsRoot = Paths .get (args [1 ]).toAbsolutePath ();
41- assert testsRoot != null ;
4229 Path dataRoot = Paths .get (args [2 ]);
43- assert dataRoot != null ;
44- Path envsRoot = Paths .get (args [3 ]);
45- assert envsRoot != null ;
30+ // allow multiple environments separated by commas
31+ List <Path > envPaths = new ArrayList <>();
32+ String envsArg = args [3 ];
33+ envsArg = envsArg .trim ();
34+ String [] envPathStrings = envsArg .split ("," );
35+ for (String envPath : envPathStrings ) {
36+ envPaths .add (Paths .get (envPath .trim ()));
37+ }
4638 boolean devMode = "true" .equals (args [4 ]);
4739 boolean genDocs = "true" .equals (args [5 ]);
4840 boolean jUnit = "true" .equals (args [6 ]);
@@ -56,27 +48,29 @@ public static void main(String... args) throws IOException, InterruptedException
5648 jvmArgs .add ("-Xmx5G" );
5749
5850 // Load environments
59- List <Environment > envs ;
60- if (Files .isDirectory (envsRoot )) {
61- envs = Files .walk (envsRoot ).filter (path -> !Files .isDirectory (path ))
51+ List <Environment > envs = new ArrayList <>();
52+ for (Path envPath : envPaths ) {
53+ if (Files .isDirectory (envPath )) {
54+ envs .addAll (Files .walk (envPath ).filter (path -> !Files .isDirectory (path ))
6255 .map (path -> {
6356 try {
64- return gson .fromJson (new String ( Files .readAllBytes (path ), StandardCharsets . UTF_8 ), Environment .class );
57+ return gson .fromJson (Files .readString (path ), Environment .class );
6558 } catch (JsonSyntaxException | IOException e ) {
6659 throw new RuntimeException (e );
6760 }
68- }).collect ( Collectors . toList ());
69- } else {
70- envs = Collections . singletonList (gson .fromJson (new String (
71- Files . readAllBytes ( envsRoot ), StandardCharsets . UTF_8 ), Environment . class ));
61+ }).toList ());
62+ } else {
63+ envs . add (gson .fromJson (Files . readString ( envPath ), Environment . class ));
64+ }
7265 }
73- System .out .println ("Test environments: " + String . join ( ", " ,
74- envs .stream ().map (Environment ::getName ).collect (Collectors .toList () )));
66+ System .out .println ("Test environments: "
67+ + envs .stream ().map (Environment ::getName ).collect (Collectors .joining ( ", " )));
7568
7669 Set <String > allTests = new HashSet <>();
77- Map <String , List <NonNullPair < Environment , String > >> failures = new HashMap <>();
70+ Map <String , List <TestError >> failures = new HashMap <>();
7871
7972 boolean docsFailed = false ;
73+ Map <Environment , TestResults > collectedResults = Collections .synchronizedMap (new HashMap <>());
8074 // Run tests and collect the results
8175 envs .sort (Comparator .comparing (Environment ::getName ));
8276 for (Environment env : envs ) {
@@ -93,16 +87,21 @@ public static void main(String... args) throws IOException, InterruptedException
9387 System .exit (3 );
9488 return ;
9589 }
96-
97- // Collect results
98- docsFailed = results .docsFailed ();
90+ collectedResults .put (env , results );
91+ }
92+
93+ // Process collected results
94+ for (var entry : collectedResults .entrySet ()) {
95+ TestResults results = entry .getValue ();
96+ Environment env = entry .getKey ();
97+ docsFailed |= results .docsFailed ();
9998 allTests .addAll (results .getSucceeded ());
10099 allTests .addAll (results .getFailed ().keySet ());
101100 for (Map .Entry <String , String > fail : results .getFailed ().entrySet ()) {
102101 String error = fail .getValue ();
103102 assert error != null ;
104103 failures .computeIfAbsent (fail .getKey (), (k ) -> new ArrayList <>())
105- .add (new NonNullPair <> (env , error ));
104+ .add (new TestError (env , error ));
106105 }
107106 }
108107
@@ -119,33 +118,33 @@ public static void main(String... args) throws IOException, InterruptedException
119118 }
120119
121120 // Sort results in alphabetical order
122- List <String > succeeded = allTests .stream ().filter (name -> !failures .containsKey (name )).collect (Collectors .toList ());
123- Collections .sort (succeeded );
121+ List <String > succeeded = allTests .stream ().filter (name -> !failures .containsKey (name )).sorted ().collect (Collectors .toList ());
124122 List <String > failNames = new ArrayList <>(failures .keySet ());
125123 Collections .sort (failNames );
126124
127125 // All succeeded tests in a single line
128126 StringBuilder output = new StringBuilder (String .format ("%s Results %s%n" , StringUtils .repeat ("-" , 25 ), StringUtils .repeat ("-" , 25 )));
129- output .append ("\n Tested environments: " + String .join (", " ,
130- envs .stream ().map (Environment ::getName ).collect (Collectors .toList ())));
131- output .append ("\n Succeeded:\n " + String .join ((jUnit ? "\n " : ", " ), succeeded ));
127+ output .append ("\n Tested environments: " ).append (envs .stream ().map (Environment ::getName ).collect (Collectors .joining (", " )));
128+ output .append ("\n Succeeded:\n " ).append (String .join ((jUnit ? "\n " : ", " ), succeeded ));
132129
133130 if (!failNames .isEmpty ()) { // More space for failed tests, they're important
134131 output .append ("\n Failed:" );
135132 for (String failed : failNames ) {
136- List <NonNullPair < Environment , String > > errors = failures .get (failed );
137- output .append ("\n " + failed + " (on " + errors .size () + " environment" + (errors .size () == 1 ? "" : "s" ) + ")" );
138- for (NonNullPair < Environment , String > error : errors ) {
139- output .append ("\n " + error .getSecond () + " (on " + error .getFirst ().getName () + ")" );
133+ List <TestError > errors = failures .get (failed );
134+ output .append ("\n " ). append ( failed ). append ( " (on " ). append ( errors .size ()). append ( " environment" ). append (errors .size () == 1 ? "" : "s" ). append ( ")" );
135+ for (TestError error : errors ) {
136+ output .append ("\n " ). append ( error .message ()). append ( " (on " ). append ( error .environment ().getName ()). append ( ")" );
140137 }
141138 }
142139 output .append (String .format ("%n%n%s" , StringUtils .repeat ("-" , 60 )));
143- System .err .print (output . toString () );
140+ System .err .print (output );
144141 System .exit (failNames .size ()); // Error code to indicate how many tests failed.
145142 return ;
146143 }
147144 output .append (String .format ("%n%n%s" , StringUtils .repeat ("-" , 60 )));
148- System .out .print (output . toString () );
145+ System .out .print (output );
149146 }
150147
148+ private record TestError (Environment environment , String message ) { }
149+
151150}
0 commit comments