本文整理汇总了C#中JSIL.Tests.ComparisonTest.RunCSharp方法的典型用法代码示例。如果您正苦于以下问题:C# ComparisonTest.RunCSharp方法的具体用法?C# ComparisonTest.RunCSharp怎么用?C# ComparisonTest.RunCSharp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSIL.Tests.ComparisonTest
的用法示例。
在下文中一共展示了ComparisonTest.RunCSharp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunComparisonTest
private CompileResult RunComparisonTest(
string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, string> errorCheckPredicate = null,
List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null,
Func<Configuration> makeConfiguration = null, Action<Exception> onTranslationFailure = null,
string compilerOptions = ""
)
{
CompileResult result = null;
Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
filename = Portability.NormalizeDirectorySeparators(filename);
try {
var testFilenames = new List<string>() { filename };
if (commonFile != null)
testFilenames.Add(commonFile);
using (var test = new ComparisonTest(
EvaluatorPool,
testFilenames,
Path.Combine(
ComparisonTest.TestSourceFolder,
ComparisonTest.MapSourceFileToTestFile(filename)
),
stubbedAssemblies, typeInfo, asmCache,
compilerOptions: compilerOptions
)) {
result = test.CompileResult;
if (shouldRunJs) {
test.Run(makeConfiguration: makeConfiguration, onTranslationFailure: onTranslationFailure);
} else {
string js;
long elapsed;
try {
var csOutput = test.RunCSharp(new string[0], out elapsed);
test.GenerateJavascript(new string[0], out js, out elapsed, makeConfiguration, onTranslationFailure);
Console.WriteLine("generated");
if (errorCheckPredicate != null) {
errorCheckPredicate(csOutput, js);
}
} catch (Exception) {
Console.WriteLine("error");
throw;
}
}
}
} catch (Exception ex) {
if (ex.Message == "JS test failed")
Debug.WriteLine(ex.InnerException);
else
Debug.WriteLine(ex);
if (failureList != null) {
failureList.Add(Path.GetFileNameWithoutExtension(filename));
} else
throw;
}
return result;
}
示例2: GenericIgnoreTest
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, string[] stubbedAssemblies = null)
{
long elapsed, temp;
string generatedJs = null, jsOutput = null;
using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
Assert.AreEqual(workingOutput, csOutput.Trim());
try {
jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration);
Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\".");
} catch (JavaScriptEvaluatorException jse) {
bool foundMatch = false;
foreach (var exc in jse.Exceptions) {
if (exc.Message.Contains(jsErrorSubstring)) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
Console.Error.WriteLine("// Was looking for a JS exception containing the string '{0}' but didn't find it.", jsErrorSubstring);
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
if (jsOutput != null)
Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput);
throw;
}
} catch {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
if (jsOutput != null)
Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput);
throw;
}
}
return generatedJs;
}
示例3: GenericTest
protected string GenericTest(
string fileName, string csharpOutput,
string javascriptOutput, string[] stubbedAssemblies = null,
TypeInfoProvider typeInfo = null
)
{
long elapsed, temp;
string generatedJs = null;
using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies, typeInfo)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
try {
var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration);
Assert.AreEqual(Portability.NormalizeNewLines(csharpOutput), csOutput.Trim(), "Did not get expected output from C# test");
Assert.AreEqual(Portability.NormalizeNewLines(javascriptOutput), jsOutput.Trim(), "Did not get expected output from JavaScript test");
} catch {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
throw;
}
}
return generatedJs;
}
示例4: GenericIgnoreTest
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, Regex[] stubbedAssemblies = null)
{
long elapsed, temp;
string generatedJs = null;
using (var test = new ComparisonTest(fileName, stubbedAssemblies)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
Assert.AreEqual(workingOutput, csOutput.Trim());
try {
test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed);
Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\".");
} catch (JavaScriptException jse) {
if (!jse.ErrorText.Contains(jsErrorSubstring))
throw;
}
}
return generatedJs;
}
示例5: GenericTest
protected string GenericTest(string fileName, string csharpOutput, string javascriptOutput, Regex[] stubbedAssemblies = null)
{
long elapsed, temp;
string generatedJs;
using (var test = new ComparisonTest(fileName, stubbedAssemblies)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed);
Assert.AreEqual(csharpOutput, csOutput.Trim(), "Did not get expected output from C# test");
Assert.AreEqual(javascriptOutput, jsOutput.Trim(), "Did not get expected output from JavaScript test");
}
return generatedJs;
}
示例6: RunComparisonTest
private IEnumerable<Metacomment> RunComparisonTest (
string filename, string[] stubbedAssemblies = null,
TypeInfoProvider typeInfo = null, Action<string, Func<string>> errorCheckPredicate = null,
List<string> failureList = null, string commonFile = null,
bool shouldRunJs = true, AssemblyCache asmCache = null,
Func<Configuration> makeConfiguration = null,
Action<Exception> onTranslationFailure = null,
JSEvaluationConfig evaluationConfig = null,
string compilerOptions = "",
Action<AssemblyTranslator> initializeTranslator = null,
Func<string> getTestRunnerQueryString = null,
bool? scanForProxies = null,
string[] extraDependencies = null,
string testFolderNameOverride = null
) {
IEnumerable<Metacomment> result = null;
Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
filename = Portability.NormalizeDirectorySeparators(filename);
try {
var testFilenames = new List<string>() { filename };
if (commonFile != null)
testFilenames.Add(commonFile);
var testDirectoryName = testFolderNameOverride??
TestContext.CurrentContext.Test.FullName.Replace(
"." + TestContext.CurrentContext.Test.Name, String.Empty);
var testFileDirectory = Path.Combine(
ComparisonTest.TestSourceFolder,
Path.GetDirectoryName(filename));
var testDirectory = Path.Combine(testFileDirectory, testDirectoryName);
Directory.CreateDirectory(testDirectory);
using (var test = new ComparisonTest(
EvaluatorPool,
testFilenames,
Path.Combine(
testDirectory,
ComparisonTest.MapSourceFileToTestFile(Path.GetFileName(filename))
),
stubbedAssemblies, typeInfo, asmCache,
compilerOptions: compilerOptions
)) {
test.GetTestRunnerQueryString = getTestRunnerQueryString ?? test.GetTestRunnerQueryString;
result = test.Metacomments;
if (extraDependencies != null) {
var destDir = Path.GetDirectoryName(test.AssemblyUtility.AssemblyLocation);
foreach (var dependency in extraDependencies)
File.Copy(dependency, Path.Combine(destDir, Path.GetFileName(dependency)), true);
}
if (shouldRunJs) {
test.Run(
makeConfiguration: makeConfiguration,
evaluationConfig: evaluationConfig,
onTranslationFailure: onTranslationFailure,
initializeTranslator: initializeTranslator,
scanForProxies: scanForProxies
);
} else {
Func<string> getJs;
long elapsed;
try {
var csOutput = test.RunCSharp(new string[0], out elapsed);
test.GenerateJavascript(
new string[0], out getJs, out elapsed,
makeConfiguration,
evaluationConfig == null || evaluationConfig.ThrowOnUnimplementedExternals,
onTranslationFailure,
initializeTranslator,
shouldWritePrologue: false
);
Console.WriteLine("generated");
if (errorCheckPredicate != null) {
errorCheckPredicate(csOutput, getJs);
}
} catch (Exception) {
Console.WriteLine("error");
throw;
}
}
}
} catch (Exception ex) {
if (ex.Message == "JS test failed")
Debug.WriteLine(ex.InnerException);
else
Debug.WriteLine(ex);
if (failureList != null) {
failureList.Add(Path.GetFileNameWithoutExtension(filename));
} else
throw;
}
return result;
}
示例7: GenericTest
protected string GenericTest(string fileName, string csharpOutput, string javascriptOutput, string[] stubbedAssemblies = null)
{
long elapsed, temp;
string generatedJs = null;
using (var test = new ComparisonTest(fileName, stubbedAssemblies)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
try {
var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed);
Assert.AreEqual(csharpOutput, csOutput.Trim(), "Did not get expected output from C# test");
Assert.AreEqual(javascriptOutput, jsOutput.Trim(), "Did not get expected output from JavaScript test");
} catch {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
throw;
}
}
return generatedJs;
}
示例8: RunComparisonTests
//.........这里部分代码省略.........
previousFailures.Add(name);
}
}
}
} catch (Exception ex) {
Console.WriteLine("Warning: Could not open registry key: {0}", ex);
}
}
var failureList = new List<string>();
var sortedFilenames = new List<string>(filenames);
sortedFilenames.Sort(
(lhs, rhs) => {
var lhsShort = Path.GetFileNameWithoutExtension(lhs);
var rhsShort = Path.GetFileNameWithoutExtension(rhs);
int result =
(previousFailures.Contains(lhsShort) ? 0 : 1).CompareTo(
previousFailures.Contains(rhsShort) ? 0 : 1
);
if (result == 0)
result = lhsShort.CompareTo(rhsShort);
return result;
}
);
var asmCache = new AssemblyCache();
foreach (var filename in sortedFilenames) {
if (filename == commonFile)
continue;
bool shouldRunJs = true;
if (testPredicate != null)
shouldRunJs = testPredicate(filename);
Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
try {
var testFilenames = new List<string>() { filename };
if (commonFile != null)
testFilenames.Add(commonFile);
using (var test = new ComparisonTest(
EvaluatorPool,
testFilenames,
Path.Combine(
ComparisonTest.TestSourceFolder,
ComparisonTest.MapSourceFileToTestFile(filename)
),
stubbedAssemblies, typeInfo, asmCache)
) {
if (shouldRunJs) {
test.Run();
} else {
string js;
long elapsed;
try {
var csOutput = test.RunCSharp(new string[0], out elapsed);
test.GenerateJavascript(new string[0], out js, out elapsed);
Console.WriteLine("ok");
if (errorCheckPredicate != null) {
errorCheckPredicate(csOutput, js);
}
} catch (Exception _exc) {
Console.WriteLine("error");
throw;
}
}
}
} catch (Exception ex) {
failureList.Add(Path.GetFileNameWithoutExtension(filename));
if (ex.Message == "JS test failed")
Debug.WriteLine(ex.InnerException);
else
Debug.WriteLine(ex);
}
}
if (callingMethod != null) {
try {
using (var rk = Registry.CurrentUser.CreateSubKey(keyName))
rk.SetValue(callingMethod.Name, String.Join(",", failureList.ToArray()));
} catch (Exception ex) {
Console.WriteLine("Warning: Could not open registry key: {0}", ex);
}
}
var ended = DateTime.UtcNow.Ticks;
var elapsedTotalSeconds = TimeSpan.FromTicks(ended - started).TotalSeconds;
Console.WriteLine("// Ran {0} test(s) in {1:000.00}s.", sortedFilenames.Count, elapsedTotalSeconds);
Assert.AreEqual(0, failureList.Count,
String.Format("{0} test(s) failed:\r\n{1}", failureList.Count, String.Join("\r\n", failureList.ToArray()))
);
}
示例9: GenericIgnoreTest
protected string GenericIgnoreTest(string fileName, string workingOutput, string jsErrorSubstring, string[] stubbedAssemblies = null)
{
long elapsed, temp;
string generatedJs = null, jsOutput = null;
using (var test = new ComparisonTest(EvaluatorPool, fileName, stubbedAssemblies)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
Assert.AreEqual(workingOutput, csOutput.Trim());
try {
jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed);
Assert.Fail("Expected javascript to throw an exception containing the string \"" + jsErrorSubstring + "\".");
} catch (JavaScriptException jse) {
if (!jse.ErrorText.Contains(jsErrorSubstring)) {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
if (jsOutput != null)
Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput);
throw;
}
} catch {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
if (jsOutput != null)
Console.Error.WriteLine("// JS output: \r\n{0}", jsOutput);
throw;
}
}
return generatedJs;
}
示例10: RunComparisonTest
private void RunComparisonTest(
string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, string> errorCheckPredicate = null,
List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null
)
{
Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
try {
var testFilenames = new List<string>() { filename };
if (commonFile != null)
testFilenames.Add(commonFile);
using (var test = new ComparisonTest(
EvaluatorPool,
testFilenames,
Path.Combine(
ComparisonTest.TestSourceFolder,
ComparisonTest.MapSourceFileToTestFile(filename)
),
stubbedAssemblies, typeInfo, asmCache)
)
{
if (shouldRunJs) {
test.Run();
} else {
string js;
long elapsed;
try
{
var csOutput = test.RunCSharp(new string[0], out elapsed);
test.GenerateJavascript(new string[0], out js, out elapsed);
Console.WriteLine("generated");
if (errorCheckPredicate != null)
{
errorCheckPredicate(csOutput, js);
}
}
catch (Exception _exc)
{
Console.WriteLine("error");
throw;
}
}
}
} catch (Exception ex) {
if (ex.Message == "JS test failed")
Debug.WriteLine(ex.InnerException);
else
Debug.WriteLine(ex);
if (failureList != null) {
failureList.Add(Path.GetFileNameWithoutExtension(filename));
} else
throw;
}
}