예제 #1
0
		/// <exception cref="System.Exception"></exception>
		public static void Run(ShellContextFactory shellContextFactory, FilePath jsFile, ShellTest.Parameters parameters, ShellTest.Status status)
		{
			Global global = new Global();
			MemoryStream @out = new MemoryStream();
			TextWriter p = new TextWriter(@out);
			global.SetOut(p);
			global.SetErr(p);
			global.DefineFunctionProperties(new string[] { "options" }, typeof(ShellTest), ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY);
			// test suite expects keywords to be disallowed as identifiers
			shellContextFactory.SetAllowReservedKeywords(false);
			ShellTest.TestState testState = new ShellTest.TestState();
			if (jsFile.GetName().EndsWith("-n.js"))
			{
				status.SetNegative();
			}
			Exception[] thrown = new Exception[] { null };
			Sharpen.Thread t = new Sharpen.Thread(new _Runnable_274(shellContextFactory, thrown, testState, status, jsFile, global), jsFile.GetPath());
			t.SetDaemon(true);
			t.Start();
			t.Join(parameters.GetTimeoutMilliseconds());
			lock (testState)
			{
				if (!testState.finished)
				{
					CallStop(t);
					status.TimedOut();
				}
			}
			int expectedExitCode = 0;
			p.Flush();
			status.OutputWas(Sharpen.Runtime.GetStringForBytes(@out.ToArray()));
			BufferedReader r = new BufferedReader(new StreamReader(new MemoryStream(@out.ToArray())));
			string failures = string.Empty;
			for (; ; )
			{
				string s = r.ReadLine();
				if (s == null)
				{
					break;
				}
				if (s.IndexOf("FAILED!") != -1)
				{
					failures += s + '\n';
				}
				int expex = s.IndexOf("EXPECT EXIT CODE ");
				if (expex != -1)
				{
					expectedExitCode = s[expex + "EXPECT EXIT CODE ".Length] - '0';
				}
			}
			if (thrown[0] != null)
			{
				status.Threw(thrown[0]);
			}
			status.ExitCodesWere(expectedExitCode, testState.exitCode);
			if (failures != string.Empty)
			{
				status.Failed(failures);
			}
		}