Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'pr60' into unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed May 4, 2019
2 parents 61b47a6 + 557a22b commit cfa914e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
38 changes: 34 additions & 4 deletions Source/Codecov.Tests/Yaml/YamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Codecov.Tests.Yaml
{
public class YamlTests
{
[Fact]
public void Should_Find_Yaml_File_If_Exits()
[WindowsFact]
public void Should_Find_Yaml_File_If_Exists_On_Windows()
{
// Given
var sourceCode = Substitute.For<ISourceCode>();
Expand All @@ -22,8 +22,23 @@ public void Should_Find_Yaml_File_If_Exits()
fileName.Should().Be("codecov.yaml");
}

[Fact]
public void Should_Return_Empty_String_If_Yaml_File_Does_Not_Exit()
[UnixFact]
public void Should_Find_Yaml_File_If_Exists_On_Unix()
{
// Given
var sourceCode = Substitute.For<ISourceCode>();
sourceCode.GetAll.Returns(new[] { @"/Fake/Class.cs", @"/Fake/Interface/IClass.cs", @"/Fake/.git", @"/Fake/codecov.yaml" });
var yaml = new Codecov.Yaml.Yaml(sourceCode);

// When
var fileName = yaml.FileName;

// Then
fileName.Should().Be("codecov.yaml");
}

[WindowsFact]
public void Should_Return_Empty_String_If_Yaml_File_Does_Not_Exit_On_Windows()
{
// Given
var sourceCode = Substitute.For<ISourceCode>();
Expand All @@ -36,5 +51,20 @@ public void Should_Return_Empty_String_If_Yaml_File_Does_Not_Exit()
// Then
fileName.Should().BeEmpty();
}

[UnixFact]
public void Should_Return_Empty_String_If_Yaml_File_Does_Not_Exit_On_Unix()
{
// Given
var sourceCode = Substitute.For<ISourceCode>();
sourceCode.GetAll.Returns(new[] { @"/Fake/Class.cs", @"/Fake/Interface/IClass.cs", @"/Fake/.git" });
var yaml = new Codecov.Yaml.Yaml(sourceCode);

// When
var fileName = yaml.FileName;

// Then
fileName.Should().BeEmpty();
}
}
}
14 changes: 11 additions & 3 deletions Source/Codecov/Yaml/Yaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using Codecov.Coverage.SourceCode;

Expand All @@ -20,14 +21,21 @@ public Yaml(ISourceCode sourceCode)

private string LoadFileName()
{
var codecovYamlFullPath = SourceCode.GetAll.FirstOrDefault(file => file.ToLower().EndsWith(@"\.codecov.yaml") || file.ToLower().EndsWith(@"\codecov.yaml") || file.ToLower().EndsWith(@"\.codecov.yml") || file.ToLower().EndsWith(@"\codecov.yml"));
var codecovYamlFullPath = SourceCode.GetAll.FirstOrDefault(file =>
{
var fileName = Path.GetFileName(file);
return fileName.Equals(".codecov.yaml", StringComparison.OrdinalIgnoreCase) ||
fileName.Equals("codecov.yaml", StringComparison.OrdinalIgnoreCase) ||
fileName.Equals(".codecov.yml", StringComparison.OrdinalIgnoreCase) ||
fileName.Equals("codecov.yml", StringComparison.OrdinalIgnoreCase);
});

if (string.IsNullOrWhiteSpace(codecovYamlFullPath))
{
return string.Empty;
}

var codecovYamlFullPathSplit = codecovYamlFullPath.Split('\\');
return !codecovYamlFullPathSplit.Any() ? string.Empty : codecovYamlFullPathSplit[codecovYamlFullPathSplit.Length - 1];
return Path.GetFileName(codecovYamlFullPath);
}
}
}

0 comments on commit cfa914e

Please sign in to comment.