Ver Fonte

Improved tests: silent mode (if not -verbose flag is used)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6854 8c9fc860-2736-0410-a75d-ab315db34111
felixf há 9 anos atrás
pai
commit
f74e4f21ca
2 ficheiros alterados com 18 adições e 4 exclusões
  1. 8 0
      source/Commands.Mod
  2. 10 4
      source/FoxTest.Mod

+ 8 - 0
source/Commands.Mod

@@ -9,6 +9,7 @@ CONST
 	(** Activate flags. *)
 	Wait* = 0;	(** Wait until the activated command returns. *)
 	InheritContext*= 1; (** Inherit context (as far as not overwritten) of the caller *)
+	Silent*= 2;
 
 	Ok* = 0;
 	CommandNotFound* = 3901;
@@ -169,6 +170,7 @@ TYPE
 
 VAR
 	emptyString : ARRAY 1 OF CHAR;
+	silentWriter: Streams.Writer;
 	trace: BOOLEAN;
 	defaultContext: Context; (* Fallback. Note that this context would be shared by different users -- may be used for tracing though *)
 
@@ -182,6 +184,9 @@ BEGIN
 	RETURN reader;
 END GetEmptyReader;
 
+PROCEDURE SendNothing(CONST buf: ARRAY OF CHAR; ofs, len: LONGINT; propagate: BOOLEAN; VAR res: LONGINT);
+END SendNothing;
+
 (** Splits a command string of the form moduleName.commandProcName into its components. Can be used to check whether a
 	command string is syntactically correct, i.e. is of the form 'ModuleName "." [ProcedureName]' *)
 
@@ -280,6 +285,8 @@ BEGIN
 		IF InheritContext IN flags THEN
 			outer := GetContext();
 			NEW(context, outer.in, arg, outer.out, outer.error, outer.caller);
+		ELSIF Silent IN flags THEN
+			NEW(context,NIL, arg, silentWriter, silentWriter, NIL);
 		ELSE
 			NEW(context, NIL, arg, NIL, NIL, NIL)
 		END;
@@ -294,6 +301,7 @@ BEGIN
 	emptyString[0] := 0X;
 	Machine.GetConfig("TraceCommands", s);
 	trace := (s[0] = "1");
+	NEW(silentWriter, SendNothing, 128);
 	NEW(defaultContext,NIL,NIL,NIL,NIL,NIL);
 END Init;
 

+ 10 - 4
source/FoxTest.Mod

@@ -1,7 +1,7 @@
 MODULE FoxTest;	(** AUTHOR "fof"; PURPOSE "Fox tester"; *)
 (* (c) fof ETH Zürich, 2008 *)
 
-IMPORT Basic := FoxBasic, TestSuite, Diagnostics, Streams, Commands, Shell, Options, Files, Strings, Versioning, CompilerInterface, Texts, TextUtilities, Modules;
+IMPORT Basic := FoxBasic, TestSuite, Diagnostics, Streams, Commands, Shell, Options, Files, Strings, Versioning, CompilerInterface, Texts, TextUtilities, Modules, KernelLog;
 
 TYPE
 	Command = ARRAY 256 OF CHAR;
@@ -12,8 +12,10 @@ TYPE
 		fileLog: Streams.Writer;
 
 		mayTrap: BOOLEAN;
+		commandFlags: SET;
 		command, prolog, epilog: Command;
 		fileName: Files.FileName;
+		dots: LONGINT;
 
 		PROCEDURE &InitTester (log, logFileWriter: Streams.Writer;  diagnostics: Diagnostics.Diagnostics; mayTrap: BOOLEAN; CONST prolog, command, epilog: Command; CONST fileName: ARRAY OF CHAR);
 		BEGIN
@@ -22,6 +24,8 @@ TYPE
 			COPY(epilog, SELF.epilog);
 			COPY(command, SELF.command);
 			COPY(fileName, SELF.fileName);
+			commandFlags := {Commands.Wait};
+			IF log = NIL THEN INCL(commandFlags, Commands.Silent) END;
 		END InitTester;
 
 		PROCEDURE Handle (r: Streams.Reader; position: LONGINT; CONST name: ARRAY OF CHAR; type: TestSuite.TestType): INTEGER;
@@ -39,16 +43,18 @@ TYPE
 			w.Update;
 			Files.Register(f);
 
+			IF log = NIL THEN KernelLog.Char("."); INC(dots); IF dots MOD 256 = 0 THEN KernelLog.Ln END; END; 
+
 			res := Commands.Ok;
 			IF prolog # "" THEN
-				Commands.Call(prolog, {Commands.Wait}, res, msg);
+				Commands.Call(prolog, commandFlags, res, msg);
 				IF (res # Commands.Ok) & (log # NIL)  THEN
 					log.String("prolog failed: "); log.String(msg); log.Ln;
 				END;
 			END;
 
 			IF (command # "") & (res = Commands.Ok) THEN
-				Commands.Call(command, {Commands.Wait}, res, msg);
+				Commands.Call(command,  commandFlags, res, msg);
 				IF res = Commands.Ok THEN
 					result := TestSuite.Positive
 				ELSIF (res < 3500) & (res >= 3440) THEN (* loader error *)
@@ -65,7 +71,7 @@ TYPE
 			END;
 
 			IF epilog # "" THEN
-				Commands.Call(epilog, {Commands.Wait}, res, msg);
+				Commands.Call(epilog,  commandFlags, res, msg);
 			END;
 
 			IF fileLog # NIL THEN