[csharp] dotnet test files added, test passing
This commit is contained in:
parent
9e590c08b7
commit
8a08a6ed56
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>7aa5a482-3954-4f97-8d72-0671795cf14e</ProjectGuid>
|
||||||
|
<RootNamespace>Antlr4.Test.DotNetCore</RootNamespace>
|
||||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
</Project>
|
||||||
|
|
|
@ -57,6 +57,12 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
public static final String newline = System.getProperty("line.separator");
|
public static final String newline = System.getProperty("line.separator");
|
||||||
public static final String pathSep = System.getProperty("path.separator");
|
public static final String pathSep = System.getProperty("path.separator");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When {@code true}, on Linux will call dotnet cli toolchain, otherwise
|
||||||
|
* will continue to use mono
|
||||||
|
*/
|
||||||
|
public static final boolean NETSTANDARD = Boolean.parseBoolean(System.getProperty("antlr-csharp-netstandard"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the {@code antlr.preserve-test-dir} runtime property is set to
|
* When the {@code antlr.preserve-test-dir} runtime property is set to
|
||||||
* {@code true}, the temporary directories created by the test run will not
|
* {@code true}, the temporary directories created by the test run will not
|
||||||
|
@ -351,15 +357,25 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compile() {
|
public boolean compile() {
|
||||||
try {
|
if(!NETSTANDARD) {
|
||||||
if(!createProject())
|
try {
|
||||||
return false;
|
if(!createProject())
|
||||||
if(!buildProject())
|
return false;
|
||||||
return false;
|
if(!buildProject())
|
||||||
return true;
|
return false;
|
||||||
} catch(Exception e) {
|
return true;
|
||||||
return false;
|
} catch(Exception e) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return createDotnetProject() && buildDotnetProject();
|
||||||
|
} catch(Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getTestProjectFile() {
|
private File getTestProjectFile() {
|
||||||
|
@ -405,7 +421,10 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
}
|
}
|
||||||
|
|
||||||
private String locateExec() {
|
private String locateExec() {
|
||||||
return new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath();
|
if (!NETSTANDARD)
|
||||||
|
return new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath();
|
||||||
|
|
||||||
|
return new File(tmpdir, "bin/Debug/netcoreapp1.0/Test.dll").getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String locateTool(String tool) {
|
private String locateTool(String tool) {
|
||||||
|
@ -472,6 +491,102 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean createDotnetProject() {
|
||||||
|
try {
|
||||||
|
String pack = BaseCSharpTest.class.getPackage().getName().replace(".", "/") + "/";
|
||||||
|
// save auxiliary files
|
||||||
|
saveResourceAsFile(pack + "AssemblyInfo.cs", new File(tmpdir, "AssemblyInfo.cs"));
|
||||||
|
saveResourceAsFile(pack + "App.config", new File(tmpdir, "App.config"));
|
||||||
|
saveResourceAsFile(pack + "Antlr4.Test.dotnet.xproj", new File(tmpdir, "Antlr4.Test.dotnet.xproj"));
|
||||||
|
saveResourceAsFile(pack + "project.json", new File(tmpdir, "project.json"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean buildDotnetProject() {
|
||||||
|
// build runtime package
|
||||||
|
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
final URL runtimeProj = loader.getResource("CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.xproj");
|
||||||
|
if ( runtimeProj==null ) {
|
||||||
|
throw new RuntimeException("C# runtime project file not found!");
|
||||||
|
}
|
||||||
|
String runtimeProjPath = runtimeProj.getPath();
|
||||||
|
runtimeProjPath = runtimeProjPath.substring(0, runtimeProjPath.lastIndexOf("/"));
|
||||||
|
runtimeProjPath = runtimeProjPath.substring(0, runtimeProjPath.lastIndexOf("/"));
|
||||||
|
String dotnetcli = locateTool("dotnet");
|
||||||
|
String[] args = {
|
||||||
|
dotnetcli,
|
||||||
|
"restore"
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean success = runProcess(args, runtimeProjPath);
|
||||||
|
|
||||||
|
args = new String[] {
|
||||||
|
dotnetcli,
|
||||||
|
"build"
|
||||||
|
};
|
||||||
|
success = runProcess(args, runtimeProjPath);
|
||||||
|
|
||||||
|
args = new String[] {
|
||||||
|
dotnetcli,
|
||||||
|
"pack"
|
||||||
|
};
|
||||||
|
success = runProcess(args, runtimeProjPath);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// build test
|
||||||
|
String tmpPackagePath = runtimeProjPath + "/bin/Debug";
|
||||||
|
try {
|
||||||
|
args = new String[] {
|
||||||
|
dotnetcli,
|
||||||
|
"restore",
|
||||||
|
"-f",
|
||||||
|
tmpPackagePath
|
||||||
|
};
|
||||||
|
boolean success = runProcess(args, tmpdir);
|
||||||
|
|
||||||
|
args = new String[] {
|
||||||
|
dotnetcli,
|
||||||
|
"build"
|
||||||
|
};
|
||||||
|
success = runProcess(args, tmpdir);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean runProcess(String[] args, String path) throws Exception {
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(args);
|
||||||
|
pb.directory(new File(path));
|
||||||
|
Process process = pb.start();
|
||||||
|
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
|
||||||
|
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
|
||||||
|
stdoutVacuum.start();
|
||||||
|
stderrVacuum.start();
|
||||||
|
process.waitFor();
|
||||||
|
stdoutVacuum.join();
|
||||||
|
stderrVacuum.join();
|
||||||
|
boolean success = process.exitValue()==0;
|
||||||
|
if ( !success ) {
|
||||||
|
this.stderrDuringParse = stderrVacuum.toString();
|
||||||
|
System.err.println("runProcess stderrVacuum: "+ this.stderrDuringParse);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
private void saveResourceAsFile(String resourceName, File file) throws IOException {
|
private void saveResourceAsFile(String resourceName, File file) throws IOException {
|
||||||
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
|
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
|
||||||
if ( input==null ) {
|
if ( input==null ) {
|
||||||
|
@ -520,8 +635,13 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
if(isWindows())
|
if(isWindows())
|
||||||
return new String[] { exec, new File(tmpdir, "input").getAbsolutePath() } ;
|
return new String[] { exec, new File(tmpdir, "input").getAbsolutePath() } ;
|
||||||
else {
|
else {
|
||||||
String mono = locateTool("mono");
|
if (!NETSTANDARD) {
|
||||||
return new String[] { mono, exec, new File(tmpdir, "input").getAbsolutePath() };
|
String mono = locateTool("mono");
|
||||||
|
return new String[] { mono, exec, new File(tmpdir, "input").getAbsolutePath() };
|
||||||
|
}
|
||||||
|
|
||||||
|
String dotnet = locateTool("dotnet");
|
||||||
|
return new String[] { dotnet, exec, new File(tmpdir, "input").getAbsolutePath() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"frameworks": {
|
||||||
|
"netcoreapp1.0": {
|
||||||
|
"imports": [
|
||||||
|
"dnxcore50"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.NETCore.App": {
|
||||||
|
"type": "platform",
|
||||||
|
"version": "1.1.0"
|
||||||
|
},
|
||||||
|
"Antlr4.Runtime.Standard": "4.6.1-*"
|
||||||
|
},
|
||||||
|
"buildOptions": {
|
||||||
|
"emitEntryPoint": true,
|
||||||
|
"outputName": "Test"
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>12962409-846e-4b80-933a-bc484d264132</ProjectGuid>
|
<ProjectGuid>12962409-846e-4b80-933a-bc484d264132</ProjectGuid>
|
||||||
<RootNamespace>Antlr4.Runtime.DotNetCore</RootNamespace>
|
<RootNamespace>Antlr4.Runtime.dotnet</RootNamespace>
|
||||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 14
|
# Visual Studio 14
|
||||||
VisualStudioVersion = 14.0.25420.1
|
VisualStudioVersion = 14.0.25420.1
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Antlr4.Runtime.DotNetCore", "Antlr4.Runtime\Antlr4.Runtime.DotNetCore.xproj", "{12962409-846E-4B80-933A-BC484D264132}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Antlr4.Runtime.dotnet", "Antlr4.Runtime\Antlr4.Runtime.dotnet.xproj", "{12962409-846E-4B80-933A-BC484D264132}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
@ -1,5 +1,18 @@
|
||||||
{
|
{
|
||||||
"version": "4.5.3-*",
|
"buildOptions": {
|
||||||
|
"nowarn": [
|
||||||
|
"CS1591"
|
||||||
|
],
|
||||||
|
"define": [
|
||||||
|
"DOTNETCORE",
|
||||||
|
"NET40PLUS",
|
||||||
|
"NET45PLUS"
|
||||||
|
],
|
||||||
|
"keyFile": "../Antlr4.snk",
|
||||||
|
"xmlDoc": true,
|
||||||
|
"outputName": "Antlr4.Runtime.Standard"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netstandard1.3": {
|
"netstandard1.3": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -7,17 +20,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"version": "4.6.1-*",
|
||||||
"buildOptions": {
|
"name": "Antlr4.Runtime.Standard"
|
||||||
"xmlDoc": true,
|
|
||||||
"keyFile": "../Antlr4.snk",
|
|
||||||
"define": [
|
|
||||||
"DOTNETCORE",
|
|
||||||
"NET40PLUS",
|
|
||||||
"NET45PLUS"
|
|
||||||
],
|
|
||||||
"nowarn": [
|
|
||||||
"CS1591"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue