Skip to content

Commit

Permalink
Merge branch 'release/6.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoproiete committed Mar 13, 2023
2 parents 66cfcdb + b431a17 commit e705240
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
- name: Set up git version
if: ${{ !contains(github.ref, '/hotfix/') && !contains(github.ref, '/release/') }}
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v0.10.2
with:
versionSpec: "5.x"
- name: Run git version
if: ${{ !contains(github.ref, '/hotfix/') && !contains(github.ref, '/release/') }}
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v0.10.2
- name: Create release branch ${{ github.event.inputs.version }}
if: ${{ steps.gitversion.outputs.majorMinorPatch }}
run: git switch -c release/${{ steps.gitversion.outputs.majorMinorPatch }}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.FileHelpers.Tests/Cake.FileHelpers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PackageReference>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cake.FileHelpers\Cake.FileHelpers.csproj" />
Expand Down
126 changes: 126 additions & 0 deletions src/Cake.FileHelpers.Tests/FileHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,132 @@ public void TestWriteAndReadLines()
Assert.Equal (contents[i], read[i]);
}

[Fact]
public void TestAppendToNewFileAndReadText()
{
const string file = "./testdata/Text.txt";
const string contents = "This is a test";

context.CakeContext.FileAppendText(file, contents);

var read = context.CakeContext.FileReadText(file);

Assert.Equal(contents, read);
}

[Fact]
public void TestAppendToExistingFileAndReadText()
{
const string file = "./testdata/Text.txt";
const string contents1 = "This is ";
const string contents2 = "a test";

context.CakeContext.FileAppendText(file, contents1);
context.CakeContext.FileAppendText(file, contents2);

var read = context.CakeContext.FileReadText(file);

Assert.Equal(contents1 + contents2, read);
}

[Fact]
public void TestAppendToNewFileAndReadTextWithUTF8Encoding()
{
const string file = "./testdata/Text.txt";
const string contents = "Monkey🐒";

context.CakeContext.FileAppendText(file, Encoding.UTF8, contents);

var read = context.CakeContext.FileReadText(file, Encoding.UTF8);

Assert.Equal(contents, read);
}

[Fact]
public void TestAppendToExistingFileAndReadTextWithUTF8Encoding()
{
const string file = "./testdata/Text.txt";
const string contents1 = "Monkey";
const string contents2 = "🐒";

context.CakeContext.FileAppendText(file, Encoding.UTF8, contents1);
context.CakeContext.FileAppendText(file, Encoding.UTF8, contents2);

var read = context.CakeContext.FileReadText(file, Encoding.UTF8);

Assert.Equal(contents1 + contents2, read);
}

[Fact]
public void TestAppendLinesToNewFileAndReadLines()
{
const string file = "./testdata/Text.txt";
var contents = new[] { "This", "is", "a", "test" };

context.CakeContext.FileAppendLines(file, contents);

var read = context.CakeContext.FileReadLines(file);

Assert.Equal(contents.Length, read.Length);

for (int i = 0; i < read.Length; i++)
Assert.Equal(contents[i], read[i]);
}

[Fact]
public void TestAppendLinesToExistingFileAndReadLines()
{
const string file = "./testdata/Text.txt";
var contents = new[] { "This", "is", "a", "test" };
var contents1 = new[] { contents[0], contents[1] };
var contents2 = new[] { contents[2], contents[3] };

context.CakeContext.FileAppendLines(file, contents1);
context.CakeContext.FileAppendLines(file, contents2);

var read = context.CakeContext.FileReadLines(file);

Assert.Equal(contents.Length, read.Length);

for (int i = 0; i < read.Length; i++)
Assert.Equal(contents[i], read[i]);
}

[Fact]
public void TestAppendLinesToNewFileAndReadLinesWithUTF8Encoding()
{
const string file = "./testdata/Text.txt";
var contents = new[] { "This is a test", "Monkey🐒" };

context.CakeContext.FileAppendLines(file, Encoding.UTF8, contents);

var read = context.CakeContext.FileReadLines(file, Encoding.UTF8);

Assert.Equal(contents.Length, read.Length);

for (int i = 0; i < read.Length; i++)
Assert.Equal(contents[i], read[i]);
}

[Fact]
public void TestAppendLinesToExistingFileAndReadLinesWithUTF8Encoding()
{
const string file = "./testdata/Text.txt";
var contents = new[] { "This is a test", "Monkey🐒" };
var contents1 = new[] { contents[0] };
var contents2 = new[] { contents[1] };

context.CakeContext.FileAppendLines(file, Encoding.UTF8, contents1);
context.CakeContext.FileAppendLines(file, Encoding.UTF8, contents2);

var read = context.CakeContext.FileReadLines(file, Encoding.UTF8);

Assert.Equal(contents.Length, read.Length);

for (int i = 0; i < read.Length; i++)
Assert.Equal(contents[i], read[i]);
}

[Fact]
public void FindTextInFilesGlob()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Cake.FileHelpers/FileHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static void FileWriteLines(this ICakeContext context, FilePath file, Enco
[CakeMethodAlias]
public static void FileAppendText (this ICakeContext context, FilePath file, string text)
{
using var streamWriter = CreateStreamWriter(context, file, FileMode.OpenOrCreate);
using var streamWriter = CreateStreamWriter(context, file, FileMode.Append);
streamWriter.Write(text);
}

Expand All @@ -149,7 +149,7 @@ public static void FileAppendText (this ICakeContext context, FilePath file, str
[CakeMethodAlias]
public static void FileAppendText(this ICakeContext context, FilePath file, Encoding encoding, string text)
{
using var streamWriter = CreateStreamWriter(context, file, FileMode.OpenOrCreate, encoding);
using var streamWriter = CreateStreamWriter(context, file, FileMode.Append, encoding);
streamWriter.Write(text);
}

Expand All @@ -162,7 +162,7 @@ public static void FileAppendText(this ICakeContext context, FilePath file, Enco
[CakeMethodAlias]
public static void FileAppendLines (this ICakeContext context, FilePath file, string[] lines)
{
using var streamWriter = CreateStreamWriter(context, file, FileMode.OpenOrCreate);
using var streamWriter = CreateStreamWriter(context, file, FileMode.Append);
WriteLines(streamWriter, lines);
}

Expand All @@ -176,7 +176,7 @@ public static void FileAppendLines (this ICakeContext context, FilePath file, st
[CakeMethodAlias]
public static void FileAppendLines(this ICakeContext context, FilePath file, Encoding encoding, string[] lines)
{
using var streamWriter = CreateStreamWriter(context, file, FileMode.OpenOrCreate, encoding);
using var streamWriter = CreateStreamWriter(context, file, FileMode.Append, encoding);
WriteLines(streamWriter, lines);
}

Expand Down

0 comments on commit e705240

Please sign in to comment.