Feature/test run settings (#3975)

* Test removal of local.testsettings

* Simplify settings

* Fix variable name + remove class attribute

* Add "DeploymentItem" attribute back

* display info when running "build_helpers.bat"

* again...

* mote test

* More logging

* Revert build_helpers.bat

* Undo some test changes

* test failed test

* Fix unit test again

* more testing

* Remove hardcoded hunspell dll files + re-add test category for spell checker test

* work

* Work on unit tests
This commit is contained in:
Nikolaj Olsson 2020-02-08 14:54:31 +01:00 committed by GitHub
parent e199d5228c
commit 47a813ae34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2494 additions and 2557 deletions

View File

@ -118,14 +118,19 @@ namespace Nikse.SubtitleEdit.Core
private static string GetBaseDirectory()
{
var assembly = System.Reflection.Assembly.GetEntryAssembly() ?? System.Reflection.Assembly.GetExecutingAssembly();
return Path.GetDirectoryName(assembly.Location) + Path.DirectorySeparatorChar;
}
private static string GetDataDirectory()
{
var appDataRoamingPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Subtitle Edit");
// hack for unit tests
var assembly = System.Reflection.Assembly.GetEntryAssembly() ?? System.Reflection.Assembly.GetExecutingAssembly();
if (assembly.Location.Contains("subtitleedit\\src\\TestResults"))
{
return assembly.Location.Substring(0, assembly.Location.IndexOf("subtitleedit\\src\\TestResults")) + @"subtitleedit\src\Test\bin\Debug";
}
var appDataRoamingPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Subtitle Edit");
if (IsRunningOnLinux || IsRunningOnMac)
{
if (!Directory.Exists(appDataRoamingPath) && !File.Exists(Path.Combine(BaseDirectory, ".PACKAGE-MANAGER")))

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="7d261dd1-82d4-4d46-aba1-c2579198fcfd" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment>
<DeploymentItem filename="packages\NHunspell.1.2.5554.16953\content\Hunspellx64.dll" />
<DeploymentItem filename="packages\NHunspell.1.2.5554.16953\content\Hunspellx86.dll" />
</Deployment>
<Execution>
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
<Properties />
</TestSettings>

View File

@ -1,20 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 14.0.23107.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleEdit", "SubtitleEdit.csproj", "{511A5B59-1C35-4719-8536-23B19AF9B21A}"
ProjectSection(ProjectDependencies) = postProject
{DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{766101A0-80D5-4560-BFF7-73F1559B4C47}"
ProjectSection(SolutionItems) = preProject
Local.testsettings = Local.testsettings
SubtitleEdit.vsmdi = SubtitleEdit.vsmdi
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{7BE5B8E8-9469-4C7C-89D7-E8C884DEFC0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateAssemblyInfo", "UpdateAssemblyInfo\UpdateAssemblyInfo.csproj", "{DBD4656C-5F40-4067-A70B-C4460DE20F77}"
@ -23,9 +16,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateLanguageFiles", "Upda
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateResourceScript", "UpdateResourceScript\UpdateResourceScript.csproj", "{2CB9698C-F0A8-42FF-8938-DE047292D5FE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E5F70420-EF49-403E-851F-700953769937}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSE", "..\libse\LibSE.csproj", "{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibSE", "..\libse\LibSE.csproj", "{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}"
ProjectSection(ProjectDependencies) = postProject
{DBD4656C-5F40-4067-A70B-C4460DE20F77} = {DBD4656C-5F40-4067-A70B-C4460DE20F77}
{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76} = {36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}
@ -73,6 +64,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E12BDE22-B6A4-4AB6-AF96-F3C0F89C15EC}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = SubtitleEdit.vsmdi
EndGlobalSection

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<RunConfiguration id="7d261dd1-82d4-4d46-aba1-c2579198fcfd" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</TestList>
</TestLists>

View File

@ -1,12 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Test
namespace Test.Dictionaries
{
[TestClass]
public class XmlDictionariesTest

View File

@ -1,13 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Forms;
using System;
using System.Collections.Generic;
using System.IO;
namespace Test
namespace Test.FixCommonErrors
{
/// <summary>
/// This is a test class for FixCommonErrors and is intended
@ -24,19 +24,19 @@ namespace Test
private Subtitle _subtitle;
private static FixCommonErrors GetFixCommonErrorsLib()
private static Nikse.SubtitleEdit.Forms.FixCommonErrors GetFixCommonErrorsLib()
{
return new FixCommonErrors();
return new Nikse.SubtitleEdit.Forms.FixCommonErrors();
}
private void InitializeFixCommonErrorsLine(FixCommonErrors target, string line)
private void InitializeFixCommonErrorsLine(Nikse.SubtitleEdit.Forms.FixCommonErrors target, string line)
{
_subtitle = new Subtitle();
_subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
target.Initialize(_subtitle, new SubRip(), System.Text.Encoding.UTF8);
}
private void InitializeFixCommonErrorsLine(FixCommonErrors target, string line, string line2)
private void InitializeFixCommonErrorsLine(Nikse.SubtitleEdit.Forms.FixCommonErrors target, string line, string line2)
{
_subtitle = new Subtitle();
_subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
@ -44,12 +44,6 @@ namespace Test
target.Initialize(_subtitle, new SubRip(), System.Text.Encoding.UTF8);
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
/// <summary>
/// Copies the contents of input to output. Doesn't close either stream.
/// </summary>
@ -63,63 +57,44 @@ namespace Test
}
}
//Use ClassInitialize to run code before running the first test in the class
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
var dictionaryFolder = Configuration.DictionariesDirectory;
if (!Directory.Exists(dictionaryFolder))
{
Directory.CreateDirectory(dictionaryFolder);
}
if (!Directory.Exists("Directories"))
Directory.CreateDirectory("Dictionaries");
var strm = asm.GetManifestResourceStream("Test.Dictionaries.en_US.aff");
if (strm != null)
var asm = System.Reflection.Assembly.GetExecutingAssembly();
var stream = asm.GetManifestResourceStream("Test.Dictionaries.en_US.aff");
if (stream != null)
{
using (Stream file = File.OpenWrite(Path.Combine("Dictionaries", "en_US.aff")))
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "en_US.aff")))
{
CopyStream(strm, file);
CopyStream(stream, file);
}
}
strm = asm.GetManifestResourceStream("Test.Dictionaries.en_US.dic");
if (strm != null)
stream = asm.GetManifestResourceStream("Test.Dictionaries.en_US.dic");
if (stream != null)
{
using (Stream file = File.OpenWrite(Path.Combine("Dictionaries", "en_US.dic")))
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "en_US.dic")))
{
CopyStream(strm, file);
CopyStream(stream, file);
}
}
strm = asm.GetManifestResourceStream("Test.Dictionaries.names.xml");
if (strm != null)
stream = asm.GetManifestResourceStream("Test.Dictionaries.names.xml");
if (stream != null)
{
using (Stream file = File.OpenWrite(Path.Combine("Dictionaries", "names.xml")))
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "names.xml")))
{
CopyStream(strm, file);
CopyStream(stream, file);
}
}
}
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion Additional test attributes
#region Merge short lines
[TestMethod]
@ -538,18 +513,6 @@ namespace Test
}
}
[TestMethod]
[TestCategory("Local")]
public void FixCommonOcrErrorsSlashIsL() // requires hardcoded rules enabled
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "The font is ita/ic!");
target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The font is italic!"); // will fail if English dictionary is not found
}
}
[TestMethod]
public void FixCommonOcrErrorsEndBoldTag()
{
@ -623,7 +586,7 @@ namespace Test
[TestMethod]
public void FixOcrErrorsViaDoNotFixToUpper()
{
using (var form = new FixCommonErrors())
using (var form = new Nikse.SubtitleEdit.Forms.FixCommonErrors())
{
Configuration.Settings.Tools.OcrFixUseHardcodedRules = true;
const string input = "i.e., your killer.";
@ -2303,56 +2266,56 @@ namespace Test
[TestMethod]
public void FixStartWithUppercaseLetterAfterPeriodInsideParagraphTest1()
{
const string ExpectedOuput = "<i>- Foobar! - What is it?</i>";
const string expectedOutput = "<i>- Foobar! - What is it?</i>";
var p = new Paragraph("<i>- Foobar! - what is it?</i>", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixStartWithUppercaseLetterAfterPeriodInsideParagraph().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixStartWithUppercaseLetterAfterPeriodInsideParagraphTest2()
{
const string ExpectedOuput = "<i>- Foobar... what is it?</i>";
var p = new Paragraph(ExpectedOuput, 1200, 5000);
const string expectedOutput = "<i>- Foobar... what is it?</i>";
var p = new Paragraph(expectedOutput, 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixStartWithUppercaseLetterAfterPeriodInsideParagraph().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixStartWithUppercaseLetterAfterPeriodInsideParagraphTest3()
{
const string ExpectedOuput = "<i>- Foobar??? What is it?</i>";
const string expectedOutput = "<i>- Foobar??? What is it?</i>";
var p = new Paragraph("<i>- Foobar??? what is it?</i>", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixStartWithUppercaseLetterAfterPeriodInsideParagraph().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixStartWithUppercaseLetterAfterPeriodInsideParagraphTest4()
{
const string ExpectedOuput = "<i>- Foobar??? 'Cause.</i>";
const string expectedOutput = "<i>- Foobar??? 'Cause.</i>";
var p = new Paragraph("<i>- Foobar??? 'cause.</i>", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixStartWithUppercaseLetterAfterPeriodInsideParagraph().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixStartWithUppercaseLetterAfterPeriodInsideParagraphTest5()
{
const string ExpectedOuput = "<i>- Foobar??? I. Lower</i>";
const string expectedOutput = "<i>- Foobar??? I. Lower</i>";
var p = new Paragraph("<i>- Foobar??? i. lower</i>", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixStartWithUppercaseLetterAfterPeriodInsideParagraph().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
@ -2410,45 +2373,45 @@ namespace Test
[TestMethod]
public void FixDanishLetterITest1()
{
const string ExpectedOuput = "Det må I undskylde.";
const string expectedOutput = "Det må I undskylde.";
var p = new Paragraph("Det må i undskylde.", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixDanishLetterI().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixDanishLetterITest2()
{
const string ExpectedOuput = "Det må I selv om.";
const string expectedOutput = "Det må I selv om.";
var p = new Paragraph("Det må i selv om.", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixDanishLetterI().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixDanishLetterITest3()
{
const string ExpectedOuput = "I dag skal I hilse på";
const string expectedOutput = "I dag skal I hilse på";
var p = new Paragraph("I dag skal i hilse på", 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixDanishLetterI().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
[TestMethod]
public void FixDanishLetterITestNegative1()
{
const string ExpectedOuput = "Der vil jeg ikke gå i skole.";
var p = new Paragraph(ExpectedOuput, 1200, 5000);
const string expectedOutput = "Der vil jeg ikke gå i skole.";
var p = new Paragraph(expectedOutput, 1200, 5000);
var s = new Subtitle();
s.Paragraphs.Add(p);
new FixDanishLetterI().Fix(s, new EmptyFixCallback());
Assert.AreEqual(ExpectedOuput, p.Text);
Assert.AreEqual(expectedOutput, p.Text);
}
#endregion

View File

@ -38,6 +38,9 @@
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="NHunspell, Version=1.2.5554.16953, Culture=neutral, PublicKeyToken=1ac793ea843b4366, processorArchitecture=MSIL">
<HintPath>..\packages\NHunspell.1.2.5554.16953\lib\net\NHunspell.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
@ -60,7 +63,7 @@
<Compile Include="Logic\NetflixQualityCheckTest.cs" />
<Compile Include="Logic\Ocr\BinaryOcrTest.cs" />
<Compile Include="Core\HtmlUtilTest.cs" />
<Compile Include="FixCommonErrorsTest.cs" />
<Compile Include="FixCommonErrors\FixCommonErrorsTest.cs" />
<Compile Include="Logic\LanguageTest.cs" />
<Compile Include="Logic\BluRaySup\BluRaySupParserTest.cs" />
<Compile Include="Logic\BluRaySup\ToolBoxTest.cs" />
@ -82,7 +85,7 @@
<Compile Include="Logic\Forms\RemoveTextForHearImpairedTest.cs" />
<Compile Include="Logic\SubtitleFormats\SubtitleFormatsTest.cs" />
<Compile Include="Logic\UtilitiesTest.cs" />
<Compile Include="XmlDictionariesTest.cs" />
<Compile Include="Dictionaries\XmlDictionariesTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\libse\LibSE.csproj">
@ -153,6 +156,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

4
src/Test/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NHunspell" version="1.2.5554.16953" targetFramework="net40" />
</packages>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Trace and Test Impact" id="94b587cd-0638-492b-8419-0a2fd0605172" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are test settings for Trace and Test Impact.</Description>
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>

View File

@ -22,7 +22,6 @@ namespace UpdateAssemblyInfo
}
};
p.OutputDataReceived += OutputDataReceived;
try
{
p.Start();