-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing the problems with the test of the Applications
- Loading branch information
Showing
39 changed files
with
747 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Project; | ||
using Xunit.Abstractions; | ||
|
||
namespace ApplicationTests | ||
{ | ||
public class BaseFileWatcherTest : IDisposable | ||
{ | ||
protected readonly ITestOutputHelper output; | ||
protected readonly string dir; | ||
protected readonly FileProject project; | ||
|
||
public BaseFileWatcherTest(ITestOutputHelper _output, string _dir) | ||
{ | ||
dir = Path.GetFullPath(_dir, Directory.GetCurrentDirectory()); | ||
Console.WriteLine("STARTING: " + dir); | ||
if (Directory.Exists(dir)) | ||
{ | ||
Directory.Delete(dir, true); | ||
} | ||
Directory.CreateDirectory(dir); | ||
output = _output; | ||
project = new FileProject(dir); | ||
project.Watch(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
project.Dispose(); | ||
Directory.Delete(dir, true); | ||
Console.WriteLine("CLEANUP: " + dir); | ||
} | ||
|
||
protected string path(string add) | ||
{ | ||
return Path.GetFullPath(add, dir); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,33 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using CLI; | ||
using Project; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ApplicationTests | ||
{ | ||
public class CreateModuleInProject: IDisposable | ||
public class CreateModuleInProject : BaseFileWatcherTest | ||
{ | ||
readonly string dir = Path.GetFullPath("CreateModuleInProject", Directory.GetCurrentDirectory()); | ||
readonly Project project; | ||
public CreateModuleInProject() | ||
public CreateModuleInProject(ITestOutputHelper output) : base(output, "CreateModuleInProject") { } | ||
|
||
[Fact] | ||
public async Task CreateModule() | ||
{ | ||
try | ||
{ | ||
Directory.Delete(dir, true); | ||
var module = await project.CreateModule("Test"); | ||
Assert.True(File.Exists(path("Test.car"))); | ||
Assert.NotNull(module); | ||
Assert.Equal("Test", module.Name); | ||
Assert.Equal(this.path("Test.car"), module.FilePath); | ||
} | ||
catch (Exception) | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine("Delete Directory failed in unit test."); | ||
Console.WriteLine(dir + ": " + ex.Message); | ||
} | ||
Directory.CreateDirectory(dir); | ||
project = new Project(dir); | ||
} | ||
|
||
[Fact] | ||
public void CreateModule() | ||
{ | ||
project.CreateModule("Test"); | ||
Assert.True(File.Exists(path("Test.car"))); | ||
|
||
/* | ||
* Modules are not automatically parsed and added to the project | ||
* when they are created. This gives you the option of using the | ||
* CLI as a very very simple "build my files" type of solution. | ||
*/ | ||
var module = project.FindModule("Test"); | ||
Assert.Null(module); | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
project.Dispose(); | ||
//Directory.Delete(dir, true); | ||
} | ||
|
||
private string path(string add) | ||
{ | ||
return Path.GetFullPath(add, dir); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using CLI; | ||
using Project; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ApplicationTests | ||
{ | ||
public class DeleteModuleInproject : BaseFileWatcherTest | ||
{ | ||
public DeleteModuleInproject(ITestOutputHelper output) : base(output, "DeleteModuleInproject") { } | ||
|
||
[Fact] | ||
public async Task CreateModule() | ||
{ | ||
try | ||
{ | ||
var module = await project.CreateModule("Test"); | ||
var filePath = module.FilePath.Clone().ToString(); | ||
var outPath = module.OutPath.Clone().ToString(); | ||
|
||
Assert.True(File.Exists(path("Test.car"))); | ||
Assert.NotNull(module); | ||
Assert.Equal("Test", module.Name); | ||
Assert.Equal(this.path("Test.car"), module.FilePath); | ||
|
||
var deleteResult = await project.DeleteModule("Test"); | ||
|
||
await Task.Delay(100); | ||
Assert.True(deleteResult); | ||
Assert.False(File.Exists(filePath)); | ||
Assert.False(Directory.Exists(outPath)); | ||
} catch (Exception ex) | ||
{ | ||
Console.WriteLine(dir + ": " + ex.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ApplicationTests | ||
{ | ||
public class MoveModuleInProject : BaseFileWatcherTest | ||
{ | ||
public MoveModuleInProject(ITestOutputHelper output) : base(output, "MoveModuleInProject") { } | ||
|
||
[Fact] | ||
public async Task MoveModule() | ||
{ | ||
try | ||
{ | ||
var module = await project.CreateModule("Test"); | ||
Assert.True(File.Exists(path("Test.car"))); | ||
Assert.NotNull(module); | ||
Assert.Equal("Test", module.Name); | ||
Assert.Equal(this.path("Test.car"), module.FilePath); | ||
|
||
var newModule = await project.MoveModule(module.Name, "Other"); | ||
var oldModule = project.FindModule("Test"); | ||
Assert.Null(oldModule); | ||
Assert.NotNull(newModule); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(dir + ": " + ex.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using CLI; | ||
using Project; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ApplicationTests | ||
{ | ||
public class ParseMultipleFiles : IDisposable | ||
public class ParseMultipleFiles : BaseFileWatcherTest | ||
{ | ||
|
||
private readonly string dir = Path.GetFullPath("ParseMultipleFiles", Directory.GetCurrentDirectory()); | ||
private readonly Project project; | ||
public ParseMultipleFiles() | ||
|
||
public ParseMultipleFiles(ITestOutputHelper output) : base(output, "ParseMultipleFiles") { } | ||
|
||
[Fact] | ||
public async Task Execute() | ||
{ | ||
try | ||
{ | ||
Directory.Delete(dir, true); | ||
} catch (Exception) { | ||
Debug.WriteLine("Delete Directory failed in unit test."); | ||
} | ||
Directory.CreateDirectory(dir); | ||
File.WriteAllText(path("First.car"), @"# The first document | ||
var tasks = new List<Task>(); | ||
tasks.Add(project.CreateModule("First", @"# The first document | ||
type Person | ||
"); | ||
File.WriteAllText(path("Second.car"), @" | ||
")); | ||
tasks.Add(project.CreateModule("Second", @" | ||
open Person | ||
# The second document | ||
type School | ||
"); | ||
|
||
project = new Project(dir); | ||
} | ||
|
||
[Fact] | ||
#pragma warning disable IDE0051 // Remove unused private members | ||
private void CreateModule() | ||
#pragma warning restore IDE0051 // Remove unused private members | ||
{ | ||
Assert.Equal(2, project.Modules.Count); | ||
var second = project.FindModule("Second"); | ||
Assert.Equal(3, second.Generator.AST.Count); | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
project.Dispose(); | ||
Directory.Delete(dir, true); | ||
")); | ||
await Task.WhenAll(tasks.ToArray()); | ||
Assert.Equal(2, project.Modules.Count); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(dir + ": " + ex.Message); | ||
} | ||
} | ||
|
||
private string path(string add) | ||
{ | ||
return Path.GetFullPath(add, dir); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.