Skip to content

Commit

Permalink
Corrigindo os testes que não estavam rodando no linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-iel committed May 17, 2024
1 parent d46da2e commit 6bfb58f
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 31 deletions.
83 changes: 77 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,91 @@

# About

Coming soon!
ByReplace is a powerful command-line interface (CLI) tool designed for efficiently executing find-and-replace operations within source files. This versatile utility enables users to seamlessly modify text within their codebase, enhancing productivity and streamlining development processes. Whether you're updating variable names, correcting typos, or implementing sweeping changes across multiple files.

# Get Started

Coming soon!
[Dotnet 8](https://dotnet.microsoft.com/en-us/download) is required to run ByReplace.
After installing the NuGet package, navigate to your terminal and execute the command `br -v`. If the installation was successful, the following text will be displayed in your terminal.

```shell
br

Commands:
apply apply commands
rule rule commands

Options:
-h, --help Show help message
--version Show version
```

## Install

Coming soon!
ByReplace tool is delivery by [nuget](https://www.nuget.org/packages/ByReplace).

```shell
dotnet install -g ByReplace
```

## How Create the Configuration File

## How create brconfig file
```shell
{
"Path": "",
"SkipDirectories": [ "" ],
"Rules": [
{
"Name": "",
"Description": "",
"Skip": [ "", "" ],
"Extensions": [ "", "" ],
"Replacement": {
"Old": [ "", "" ],
"New": ""
}
}
]
}
```

Coming soon!
### Path

### SkipDirectories

### Rules

## Commands

Coming soon!
### Apply

`br apply rule`: Is used to execute only one rule from brConfiguration file.

- `-r`: rule's name.
- `-p`: path of files to execute the apply.
- `-f`: folder's path that constains the brConfiguration file.

```shell
br apply rule -r "Rule" -p "C:/{three files" -f "C:"
```

`br apply rules`: Is used to execute all rules rule from brConfiguration file.

- `-p`: path of files to execute the apply.
- `-f`: folder's path that constains the brConfiguration file.

```shell
br apply rules -p "C:/{three files" -f "C:"
```

### Rule

`br rule list-rules`

```shell
```

`br rule open-rule`

```shell
```
25 changes: 13 additions & 12 deletions src/ByReplace.Test/Analyzers/AnalyzerRunnerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public void RunAnalysis_MapAllRulesThatMatchToFileInSourceTree_ShouldReturnRules
Assert.Equal(4, analyzersAndFixers.Count);

Assert.Collection(analyzersAndFixers,
entry =>
{
Assert.Equal("bin2.txt", entry.Key.Name);
Assert.Equal(".txt", entry.Key.Extension);
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name));
},
entry =>
{
Assert.Equal("obj1.txt", entry.Key.Name);
Assert.Equal(".txt", entry.Key.Extension);
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name));
},

entry =>
{
Assert.Equal("RootFile1.cs", entry.Key.Name);
Expand All @@ -95,18 +108,6 @@ public void RunAnalysis_MapAllRulesThatMatchToFileInSourceTree_ShouldReturnRules
Assert.Equal("RootFile2.cs", entry.Key.Name);
Assert.Equal(".cs", entry.Key.Extension);
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name));
},
entry =>
{
Assert.Equal("bin2.txt", entry.Key.Name);
Assert.Equal(".txt", entry.Key.Extension);
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name));
},
entry =>
{
Assert.Equal("obj1.txt", entry.Key.Name);
Assert.Equal(".txt", entry.Key.Extension);
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name));
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/ByReplace.Test/Models/BrConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public void SetOnlyOneRule_WhenSetNewRule_ShouldReplaceOldRulesWithTheNewOne()
public void ChangeDefaultPath_WhenChangePathToAPathThatExists_ShouldReplaceTheValueOfPath()
{
// Arrange
var config = new BrConfiguration("C://ByReplace", ["**//Controllers/*"], []);
var config = new BrConfiguration("./ByReplace", ["**//Controllers/*"], []);

// Act
config.ChangeDefaultPath("C:");
config.ChangeDefaultPath("./");

// Assert
Assert.Equal("C:", config.Path);
Assert.Equal("./", config.Path);
}

[Fact]
Expand Down
6 changes: 5 additions & 1 deletion src/ByReplace/Analyzers/AnalyzerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ internal AnalyzerAndFixer RunAnalysis(ImmutableList<DirectoryNode> directoryThre
analyzersAndFixers.TryMatchRule(dir, brConfiguration.Rules);
}

return analyzersAndFixers;
return new AnalyzerAndFixer(
analyzersAndFixers
.OrderBy(x => x.Key.FullName)
.ToDictionary(x => x.Key, x => x.Value), print);

}
}
4 changes: 2 additions & 2 deletions src/ByReplace/ByReplace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<Description>CLI to help developer to do bulk replace using shared configuration.</Description>
<Authors>Daniel-iel</Authors>
<Company>Daniel-iel</Company>
<Authors>Daniel Oliveira</Authors>
<Company>Daniel Oliveira</Company>
<ToolCommandName>br</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
49 changes: 49 additions & 0 deletions src/ByReplace/Common/PathFixer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Runtime.InteropServices;

namespace ByReplace.Common;

internal class PathFixer
{
public string OS
{
get
{
return Environment.OSVersion.ToString();
}
}

public string GetFixedPath(params string[] parts)
{
IPathFixer linux = new PathFixerLinux();
IPathFixer windows = new PathFixerLinux();

return RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? linux.PathFixed(parts)
: windows.PathFixed(parts);
}
}

internal interface IPathFixer
{
string PathFixed(params string[] parts);
}

internal class PathFixerWindowns : IPathFixer
{
public string PathFixed(params string[] parts)
{
return string
.Join('\\', parts)
.Trim();
}
}

internal class PathFixerLinux : IPathFixer
{
public string PathFixed(params string[] parts)
{
return string
.Join('/', parts)
.Trim();
}
}
8 changes: 6 additions & 2 deletions src/ByReplace/Models/BrConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[assembly: InternalsVisibleTo("ByReplace.Test")]
using ByReplace.Common;

[assembly: InternalsVisibleTo("ByReplace.Test")]

namespace ByReplace.Models;

Expand Down Expand Up @@ -34,7 +36,9 @@ public void ChangeDefaultPath(string path)

public static BrConfiguration GetConfiguration(string pathConfig)
{
string configurationFilePath = Sanitizer(string.Join(@"\", pathConfig, "brconfig.json"));
PathFixer path = new PathFixer();

string configurationFilePath = path.GetFixedPath(pathConfig, "brconfig.json");

if (!File.Exists(configurationFilePath))
{
Expand Down
11 changes: 6 additions & 5 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ RUN dotnet restore ByReplace.sln
RUN dotnet build ByReplace.sln -c Release -o /app
RUN dotnet test ByReplace.sln

# # Build runtime image
# FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
# WORKDIR /app
# COPY --from=build /app .
# ENTRYPOINT ["dotnet", "ByReplace.dll"]
# Build runtime image
#FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
#WORKDIR /app
#COPY --from=build /app .
#ENTRYPOINT ["dotnet", "ByReplace.dll"]
#

0 comments on commit 6bfb58f

Please sign in to comment.