Пример #1
0
 public string Replace(string realSql, ReplaceEval action)
 {
     if (!_sqlParamsTokens.IsMatch(realSql))
     {
         return(realSql);
     }
     return(_sqlParamsTokens.Replace(realSql, match =>
     {
         string paramName = match.Groups[1].Value;
         string nameWithPrefix = match.Value;
         return action(paramName, nameWithPrefix);
     }));
 }
Пример #2
0
        public String Replace(StatementType statementType, string sql, ReplaceEval replaceEval)
        {
            switch (statementType)
            {
            case StatementType.Insert:
            {
                return(_insertTokens.Replace(sql, match =>
                    {
                        var operation = match.Groups[1].Value;
                        var tableName = match.Groups[2].Value;
                        return replaceEval(tableName, operation);
                    }));
            }

            case StatementType.Update:
            {
                return(_updateTokens.Replace(sql, match =>
                    {
                        var operation = match.Groups[1].Value;
                        var tableName = match.Groups[2].Value;
                        return replaceEval(tableName, operation);
                    }));
            }

            case StatementType.Delete:
            {
                return(_deleteTokens.Replace(sql, match =>
                    {
                        var operation = match.Groups[1].Value + match.Groups[2].Value;
                        var tableName = match.Groups[3].Value;
                        return replaceEval(tableName, operation);
                    }));
            }

            default: throw new ArgumentException();
            }
        }
Пример #3
0
        static void RunTest(string test)
        {
            string target = Path.Combine(config.test_dir, "jstest.js");

            ReplaceEval    repl_eval    = new ReplaceEval();
            MatchEvaluator replace_eval = new MatchEvaluator(repl_eval.replace_eval);

            StreamReader source_io = File.OpenText(test);
            string       source;

            try {
                source = source_io.ReadToEnd();
            } finally {
                source_io.Close();
            }

            source = Regex.Replace(source, @"eval\s*\(([""'])(.+?[^\\]?)\1\s*\)", replace_eval).
                     Replace("new TestCase", "TestCase");
            string eval_funs = repl_eval.eval_funs.ToString();

            StreamWriter target_io = File.CreateText(target);

            try {
                target_io.WriteLine(preamble);
                target_io.WriteLine(eval_funs);
                target_io.WriteLine(source);
            } finally {
                target_io.Close();
            }

            // Luckily, we don't have to deal with multiple threads here...
            string old_dir = Environment.CurrentDirectory;

            Environment.CurrentDirectory = config.test_dir;
            {
                Console.WriteLine();
                Console.WriteLine("Running {0}...", test);

                ProcessStartInfo compiler_info = new ProcessStartInfo(config.compile_cmd, config.compile_args);
                compiler_info.CreateNoWindow         = true;
                compiler_info.UseShellExecute        = false;
                compiler_info.RedirectStandardOutput = true;
                compiler_info.RedirectStandardError  = true;
                Process compiler = Process.Start(compiler_info);
                compiler.WaitForExit();
                Console.Write(compiler.StandardOutput.ReadToEnd());
                Console.Write(compiler.StandardError.ReadToEnd());
                if (compiler.ExitCode != 0 || !File.Exists("jstest.exe"))
                {
                    Failed(test, String.Format("compiler aborted with exit code {0}", compiler.ExitCode));
                    goto done;
                }

                ProcessStartInfo runtime_info = new ProcessStartInfo(config.run_cmd, config.run_args);
                runtime_info.CreateNoWindow         = true;
                runtime_info.UseShellExecute        = false;
                runtime_info.RedirectStandardOutput = true;
                runtime_info.RedirectStandardError  = true;
                Process runtime = Process.Start(runtime_info);
                // For some reason we need the timeout here even if the runtime does not need longer than it...
                runtime.WaitForExit(5000);

                Console.Write(runtime.StandardOutput.ReadToEnd());
                Console.Write(runtime.StandardError.ReadToEnd());
                if (runtime.ExitCode != 0)
                {
                    Failed(test, String.Format("runtime aborted with exit code {0}", runtime.ExitCode));
                }
                File.Delete("jstest.exe");
            }

done:
            Environment.CurrentDirectory = old_dir;
        }
Пример #4
0
		static void RunTest (string test)
		{
			string target = Path.Combine (config.test_dir, "jstest.js");

			ReplaceEval repl_eval = new ReplaceEval ();
			MatchEvaluator replace_eval = new MatchEvaluator (repl_eval.replace_eval);

			StreamReader source_io = File.OpenText (test);
			string source;
			try {
				source = source_io.ReadToEnd ();
			} finally {
				source_io.Close ();
			}

			source = Regex.Replace (source, @"eval\s*\(([""'])(.+?[^\\]?)\1\s*\)", replace_eval).
				Replace ("new TestCase", "TestCase");
			string eval_funs = repl_eval.eval_funs.ToString ();

			StreamWriter target_io = File.CreateText (target);
			try {
				target_io.WriteLine (preamble);
				target_io.WriteLine (eval_funs);
				target_io.WriteLine (source);
			} finally {
				target_io.Close ();
			}

			// Luckily, we don't have to deal with multiple threads here...
			string old_dir = Environment.CurrentDirectory;
			Environment.CurrentDirectory = config.test_dir;
			{
				Console.WriteLine ();
				Console.WriteLine ("Running {0}...", test);

				ProcessStartInfo compiler_info = new ProcessStartInfo (config.compile_cmd, config.compile_args);
				compiler_info.CreateNoWindow = true;
				compiler_info.UseShellExecute = false;
				compiler_info.RedirectStandardOutput = true;
				compiler_info.RedirectStandardError = true;
				Process compiler = Process.Start (compiler_info);
				compiler.WaitForExit ();
				Console.Write (compiler.StandardOutput.ReadToEnd ());
				Console.Write (compiler.StandardError.ReadToEnd ());
				if (compiler.ExitCode != 0 || !File.Exists ("jstest.exe")) {
					Failed (test, String.Format ("compiler aborted with exit code {0}", compiler.ExitCode));
					goto done;
				}

				ProcessStartInfo runtime_info = new ProcessStartInfo (config.run_cmd, config.run_args);
				runtime_info.CreateNoWindow = true;
				runtime_info.UseShellExecute = false;
				runtime_info.RedirectStandardOutput = true;
				runtime_info.RedirectStandardError = true;
				Process runtime = Process.Start (runtime_info);
				// For some reason we need the timeout here even if the runtime does not need longer than it...
				runtime.WaitForExit (5000);

				Console.Write (runtime.StandardOutput.ReadToEnd ());
				Console.Write (runtime.StandardError.ReadToEnd ());
				if (runtime.ExitCode != 0)
					Failed (test, String.Format ("runtime aborted with exit code {0}", runtime.ExitCode));
				File.Delete ("jstest.exe");
			}

			done:
			Environment.CurrentDirectory = old_dir;
		}