Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
Add configuration to build metadata so unit tests actually look in correct build folder for files.

Replace debug.writeline with trace.writeline so that
console output is available for release mode tests
as well.

Make master audio utility constructor more resiliant now that we no
longer wvunpack to be present in a system.

Work done for #196
  • Loading branch information
atruskie committed Mar 25, 2020
1 parent 14859ff commit 9e78583
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 112 deletions.
6 changes: 3 additions & 3 deletions ap.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// "tests": true,
// "TestResults": true
},
"files.associations": {
"**/build/azure*yml": "azure-pipelines"
},
// "files.associations": {
// "**/build/azure*yml": "azure-pipelines"
// },
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.enableEditorConfigSupport": true,
"editor.formatOnType": true,
Expand Down
3 changes: 0 additions & 3 deletions build/azure-pipelines-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:
- ${{ each platform in parameters.platforms }}:
- ${{ each configuration in platform.configurations }}:
- job:
# rid: ${{ platform.rid }}
# pool: ${{ platform.pool }}
# configuration: ${{ configuration }}
displayName: Build ${{ format('{0}_{1}_{2}', platform.rid, platform.pool, configuration) }}
continueOnError: ${{ coalesce(platform.continueOnError, 'false') }}
pool:
Expand Down
16 changes: 9 additions & 7 deletions src/Acoustics.Tools/Audio/MasterAudioUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public class MasterAudioUtility : AbstractAudioUtility, IAudioUtility
/// </summary>
public MasterAudioUtility()
{
this.wvunpackUtility = new WavPackAudioUtility(new FileInfo(AppConfigHelper.WvunpackExe));
this.wvunpackUtility = AppConfigHelper.WvunpackExe != null
? new WavPackAudioUtility(AppConfigHelper.WvunpackExe.ToFileInfo())
: null;

this.ffmpegUtility = new FfmpegAudioUtility(new FileInfo(AppConfigHelper.FfmpegExe), new FileInfo(AppConfigHelper.FfprobeExe));
this.ffmpegRawPcmUtility = new FfmpegRawPcmAudioUtility(new FileInfo(AppConfigHelper.FfmpegExe));
this.soxUtility = new SoxAudioUtility(new FileInfo(AppConfigHelper.SoxExe));

this.TemporaryFilesDirectory = this.TemporaryFilesDirectory ?? TempFileHelper.TempDir();
this.TemporaryFilesDirectory ??= TempFileHelper.TempDir();

this.Validate();
}
Expand Down Expand Up @@ -191,11 +193,11 @@ public override void Modify(FileInfo source, string sourceMediaType, FileInfo ou
}

var segmentRequest = new AudioUtilityRequest
{
OffsetStart = request.OffsetStart,
OffsetEnd = request.OffsetEnd,
MixDownToMono = false,
};
{
OffsetStart = request.OffsetStart,
OffsetEnd = request.OffsetEnd,
MixDownToMono = false,
};

FileInfo soxSourceFile;
var soxRequest = request;
Expand Down
2 changes: 0 additions & 2 deletions src/AnalysisPrograms/CheckEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ private int Execute(Arguments arguments)
errors.Add(message);
}


Type type = Type.GetType("Mono.Runtime");
if (type != null)
{
errors.Add($"We no longer use Mono with ${Meta.Name}. DO NOT prefix the {Meta.Name} prefix with `mono`.");
}


// don't have much more to check at the current time
if (errors.Count == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/AssemblyMetadata.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace AnalysisPrograms

public const bool CompiledAsSelfContained = ${self_contained};
public const string CompiledRuntimeIdentifer = "${runtime_identifer}";

public const string CompiledConfiguration = "${configuration}";

public static readonly Version Version = new Version("${version}");
}
Expand Down
10 changes: 6 additions & 4 deletions src/git_version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#Requires -Version 6

param(
[string]$configuration = "Release",

[string]$configuration,
[string]$self_contained,
[string]$runtime_indentifier
)
Expand Down Expand Up @@ -35,14 +36,14 @@ $describe = git describe --dirty --abbrev --long --always

$describe_tag, $describe_commit_count, $describe_hash, $describe_dirty = $describe.Split("-")
$is_dirty = if ($null -ne $describe_dirty) { 'true' } else { 'false' }
$dirty = if ($is_dirty) { 'DIRTY'} else { '' }
$dirty = if ($is_dirty) { 'DIRTY' } else { '' }

$year = $now.Year
$month = $now.Month
$short_year = $now.ToString("yy")
$short_month = $now.ToString("%M")
$build_date = $now.ToString("O")
$build_number = if ($null -eq ${env:BUILD_BUILDID}) { "000" } else { ${env:BUILD_BUILDID} }
$build_number = if ($null -eq ${env:BUILD_BUILDID}) { "000" } else { ${env:BUILD_BUILDID} }

$tags_this_month = git log --tags --simplify-by-decoration --first-parent --pretty="format:%ai %d" --after="$year-$month-01T00:00Z"
$tag_count_this_month = $tags_this_month.Count
Expand All @@ -55,7 +56,7 @@ $content = Get-Content -Raw $template_file
$templated = $ExecutionContext.InvokeCommand.ExpandString($content)
$templated | Out-File $metadata_file -Force -Encoding utf8NoBOM

$props = @"
$props = @"
Year=$short_year
Month=$short_month
BuildDate=$build_date
Expand All @@ -73,6 +74,7 @@ GeneratedMetadata=$metadata_file
CacheWarning=$cache_warning
MsBuildSelfContained=$self_contained
MsBuildRuntimeIdentifer=$runtime_identifer
MsBuildConfiguration=$configuration
"@

Write-Output $props
Expand Down
6 changes: 3 additions & 3 deletions tests/Acoustics.Test/AnalysisBase/AnalysisCoordinatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ private void TestAnalysisCoordinatorPaths(SaveBehavior wav, bool unique, Directo
var dummyAnalyzer = new DummyAnalyzer(true);
var settings = dummyAnalyzer.DefaultSettings;

Debug.WriteLine("Class output directory:" + this.TestOutputDirectory.FullName);
Trace.WriteLine("Class output directory:" + this.TestOutputDirectory.FullName);

settings.AnalysisMaxSegmentDuration = 60.Seconds();
settings.AnalysisOutputDirectory = this.AnalysisOutput;
Expand Down Expand Up @@ -894,15 +894,15 @@ private void AssertFilesAreAsExpected(int stage, State state, CoordinatorPathTes
foreach (var file in state.ShouldExist)
{
var f = file.FormatToken(paths);
Debug.WriteLine(f);
Trace.WriteLine(f);

Assert.That.PathExists(f, $"(stage: {stage}, pre-templated string: \"{file}\")");
}

foreach (var file in state.ShouldNotExist)
{
var f = file.FormatToken(paths);
Debug.WriteLine(f);
Trace.WriteLine(f);
Assert.That.PathNotExists(file, $"(stage: {stage}, pre-templated string: \"{file}\")");
}
}
Expand Down
12 changes: 7 additions & 5 deletions tests/Acoustics.Test/AnalysisPrograms/MainEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public async Task CheckEnvironmentWorks()
using var console = new ConsoleRedirector();
var code = await MainEntry.Main(new[] { "CheckEnvironment" });

Trace.WriteLine(console.Lines);

Assert.AreEqual(0, code);

this.AssertContainsCopyright(console.Lines);
Expand Down Expand Up @@ -120,7 +122,7 @@ public void TestConfigCanBeLoadedWithShortName()

const string shortName = "ANALYS~1.EXE";

Debug.WriteLine("Executing in: " + PathHelper.AnalysisProgramsBuild);
Trace.WriteLine("Executing in: " + PathHelper.AnalysisProgramsBuild);
Process process = new Process
{
StartInfo = new ProcessStartInfo(shortName, $"{CheckEnvironment.CommandName} -n")
Expand All @@ -141,13 +143,13 @@ public void TestConfigCanBeLoadedWithShortName()
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();

Debug.WriteLine("Output:\n" + output);
Debug.WriteLine("Error:\n" + error);
Trace.WriteLine("Output:\n" + output);
Trace.WriteLine("Error:\n" + error);

StringAssert.Contains(output,
"!!!IMPORTANT: Executable name is ANALYS~1.EXE and expected name is AnalysisPrograms.exe");
Assert.IsFalse(output.Contains("ReflectionTypeLoadException"),$"Output should not contain `ReflectionTypeLoadException`.");
Assert.IsFalse(error.Contains("ReflectionTypeLoadException"),$"Output should not contain `ReflectionTypeLoadException`.");
Assert.IsFalse(output.Contains("ReflectionTypeLoadException"), $"Output should not contain `ReflectionTypeLoadException`.");
Assert.IsFalse(error.Contains("ReflectionTypeLoadException"), $"Output should not contain `ReflectionTypeLoadException`.");

Assert.AreEqual(0, process.ExitCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void TestConfigSerialization()
CollectionAssert.Contains(lines, " TestBlob: !BlobParameters");
CollectionAssert.Contains(lines, " TestWhistle: !WhistleParameters");

//lines.ForEach(x => Debug.WriteLine(x));
//lines.ForEach(x => Trace.WriteLine(x));

var config2 = Yaml.Deserialize<GenericRecognizer.GenericRecognizerConfig>(target);

Expand Down
4 changes: 2 additions & 2 deletions tests/Acoustics.Test/ArrayExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void TestArrayFill()
}

stopwatch.Stop();
Debug.WriteLine("Time taken:" + stopwatch.Elapsed);
Trace.WriteLine("Time taken:" + stopwatch.Elapsed);

Assert.IsTrue(testArray.All(value => value == 4.123456));
}
Expand All @@ -58,7 +58,7 @@ public void TestArrayFastFill()
}

stopwatch.Stop();
Debug.WriteLine("Time taken:" + stopwatch.Elapsed);
Trace.WriteLine("Time taken:" + stopwatch.Elapsed);

Assert.IsTrue(testArray.All(value => value == 4.123456));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void TestFeatureLearning()
FileInfo f = filePath.ToFileInfo();
if (f.Length == 0)
{
Debug.WriteLine(f.Name);
Trace.WriteLine(f.Name);
}
}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public void TestLeftPaddingInLowerLayers()

tiler.Tile(superTile);

////Debug.WriteLine(this.outputDirectory.FullName);
////Debug.WriteLine(this.outputDirectory.GetFiles().Length);
////Trace.WriteLine(this.outputDirectory.FullName);
////Trace.WriteLine(this.outputDirectory.GetFiles().Length);
var actualFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray();

Assert.AreEqual(8, actualFiles.Length);
Expand Down Expand Up @@ -158,8 +158,8 @@ public void TestItShouldCutAndPadRightWithTransparency()
var superTile = new DefaultSuperTile() { Image = testBitmap, OffsetX = 0, Scale = 60.0 };
this.tiler.Tile(superTile);

////Debug.WriteLine(this.outputDirectory.FullName);
////Debug.WriteLine(this.outputDirectory.GetFiles().Length);
////Trace.WriteLine(this.outputDirectory.FullName);
////Trace.WriteLine(this.outputDirectory.GetFiles().Length);
var producedFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray();

Assert.AreEqual(24, producedFiles.Length);
Expand Down Expand Up @@ -198,8 +198,8 @@ public void TestPaddingANonBlockTime()
};
this.tiler.Tile(superTile);

////Debug.WriteLine(this.outputDirectory.FullName);
////Debug.WriteLine(this.outputDirectory.GetFiles().Length);
////Trace.WriteLine(this.outputDirectory.FullName);
////Trace.WriteLine(this.outputDirectory.GetFiles().Length);
var producedFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray();

Assert.AreEqual(25, producedFiles.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void Test60Resolution()
TimeSpan.Zero);
this.tiler.Tile(superTile);

////Debug.WriteLine(this.outputDirectory.FullName);
////Debug.WriteLine(this.outputDirectory.GetFiles().Length);
////Trace.WriteLine(this.outputDirectory.FullName);
////Trace.WriteLine(this.outputDirectory.GetFiles().Length);
var producedFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray();

Assert.AreEqual(6, producedFiles.Length);
Expand Down Expand Up @@ -218,8 +218,8 @@ public void Test1Resolution()
TimeSpan.FromHours(1));
this.tiler.Tile(superTile);

////Debug.WriteLine(this.outputDirectory.FullName);
////Debug.WriteLine(this.outputDirectory.GetFiles().Length);
////Trace.WriteLine(this.outputDirectory.FullName);
////Trace.WriteLine(this.outputDirectory.GetFiles().Length);
var producedFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray();

Assert.AreEqual(12, producedFiles.Length);
Expand Down
12 changes: 6 additions & 6 deletions tests/Acoustics.Test/InfiniteTextStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class InfiniteTextStreamTests

public void InfiniteStreamIsInfinite()
{
Debug.WriteLine("Generating output");
Trace.WriteLine("Generating output");

var builder = new StringBuilder(1_000_000);
var source = new CancellationTokenSource();
Expand Down Expand Up @@ -59,18 +59,18 @@ void Generate()
Assert.IsTrue(work.IsCompleted);

string s = builder.ToString();
Debug.WriteLine($"Generation complete (length: {s.Length}):");
Trace.WriteLine($"Generation complete (length: {s.Length}):");

Assert.IsTrue(s.Length > 1_000, $"Length {s.Length} was not greater than expected length of 1000");

//Debug.WriteLine(s);
//Trace.WriteLine(s);
}

[TestMethod]
[Timeout(5_000)]
public void InfiniteStreamCanReadLines()
{
Debug.WriteLine("Generating output");
Trace.WriteLine("Generating output");

StringBuilder builder = new StringBuilder(1_000_000);
var source = new CancellationTokenSource();
Expand Down Expand Up @@ -100,11 +100,11 @@ void Generate()
Assert.IsTrue(work.IsCompleted);

string s = builder.ToString();
Debug.WriteLine($"Generation complete (length: {s.Length}:");
Trace.WriteLine($"Generation complete (length: {s.Length}:");

Assert.IsTrue(s.Length > 10_000);

//Debug.WriteLine(s);
//Trace.WriteLine(s);
}
}
}
2 changes: 1 addition & 1 deletion tests/Acoustics.Test/RuntimesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void TestAssemblyMetadataHasBeenGenerated()
// This won't fail if a build stops generating build data immediately, but the time
// it takes to commit->push->run on ci should definitely trigger the failure.
var generatedBuildData = Path.GetFullPath(Path.Combine(PathHelper.SolutionRoot, "src", "AssemblyMetadata.Generated.cs"));
Debug.WriteLine(generatedBuildData);
Trace.WriteLine(generatedBuildData);
var actual = File.GetLastWriteTimeUtc(generatedBuildData);
Assert.That.AreEqual(now, actual, TimeSpan.FromMinutes(5));

Expand Down
Loading

0 comments on commit 9e78583

Please sign in to comment.