Skip to content

Commit

Permalink
Merge pull request #385 from mattjphillips/fail_on_compiler_error
Browse files Browse the repository at this point in the history
When a compilation error occurs, fail any of the tests that are based on...
  • Loading branch information
nikhilk committed Jun 23, 2013
2 parents 6dae908 + 1d33e49 commit a8b0a36
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/Core/BrowserTest.cs
Expand Up @@ -22,6 +22,7 @@ public abstract class BrowserTest {
private static readonly string[] _codeFiles = new string[] {
"OOP.cs"
};
private static string _compilationFailures;

private const int _port = 3976;

Expand All @@ -40,16 +41,24 @@ public abstract class BrowserTest {
File.Copy(Path.Combine(binDirectory, script), Path.Combine(scriptsDirectory, script), overwrite: true);
}

List<string> codeFailures = new List<string>();

string mscorlibPath = Path.Combine(binDirectory, "mscorlib.dll");
foreach (string codeFile in _codeFiles) {
string script = Path.GetFileNameWithoutExtension(codeFile) + Path.ChangeExtension(".cs", ".js");

SimpleCompilation compilation = new SimpleCompilation(Path.Combine(scriptsDirectory, script));
compilation.AddReference(mscorlibPath)
bool result = compilation.AddReference(mscorlibPath)
.AddSource(Path.Combine(codeDirectory, codeFile))
.Execute();

if (!result) {
codeFailures.Add(codeFile);
}
}

_compilationFailures = (codeFailures.Count == 0) ? null : string.Join(", ", codeFailures);

_webTest = new WebTest();
_webTest.StartWebServer(_port, webRoot);
}
Expand All @@ -64,6 +73,11 @@ public abstract class BrowserTest {
}

protected void RunTest(string url) {
if (_compilationFailures != null) {
Assert.Fail("Could not run test due to compilation failure of " + _compilationFailures + ".");
return;
}

Uri testUri = _webTest.GetTestUri(url);

WebTestResult result = _webTest.RunTest(testUri, WebBrowser.Chrome);
Expand Down

0 comments on commit a8b0a36

Please sign in to comment.