actions build and test v003

also adds a console runner for testing arbitrary files
This commit is contained in:
Eliot Jones 2021-02-28 17:03:32 -04:00
parent d5be096130
commit 3437b48925
4 changed files with 117 additions and 1 deletions

View File

@ -11,7 +11,7 @@ jobs:
- name: Set up dotnet core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "2.0.x"
dotnet-version: "2.1.x"
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2

View File

@ -0,0 +1,73 @@
using System;
using System.IO;
using System.Text;
using Console = System.Console;
namespace UglyToad.PdfPig.ConsoleRunner
{
public static class Program
{
public static int Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Only 1 argument, path to test file directory, may be provided.");
return 7;
}
var path = args[0];
if (!Directory.Exists(path))
{
Console.WriteLine($"The provided path is not a valid directory: {path}.");
return 7;
}
var hasError = false;
var errorBuilder = new StringBuilder();
var fileList = Directory.GetFiles(path, "*.pdf");
foreach (var file in fileList)
{
try
{
var numWords = 0;
var numPages = 0;
using (var pdfDocument = PdfDocument.Open(file))
{
foreach (var page in pdfDocument.GetPages())
{
numPages++;
foreach (var word in page.GetWords())
{
if (word != null)
{
numWords++;
}
}
}
}
Console.WriteLine($"Read {numWords} words on {numPages} pages in document {file}.");
}
catch (Exception ex)
{
hasError = true;
errorBuilder.AppendLine($"Parsing document {file} failed due to an error.")
.Append(ex)
.AppendLine();
}
}
if (hasError)
{
Console.WriteLine(errorBuilder.ToString());
return 5;
}
Console.WriteLine("Complete! :)");
return 0;
}
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\UglyToad.PdfPig\UglyToad.PdfPig.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UglyToad.PdfPig.ConsoleRunner", "UglyToad.PdfPig.ConsoleRunner.csproj", "{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UglyToad.PdfPig", "..\..\src\UglyToad.PdfPig\UglyToad.PdfPig.csproj", "{4E37F4FA-4127-48C8-9151-235307C820E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Release|Any CPU.Build.0 = Release|Any CPU
{4E37F4FA-4127-48C8-9151-235307C820E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E37F4FA-4127-48C8-9151-235307C820E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E37F4FA-4127-48C8-9151-235307C820E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E37F4FA-4127-48C8-9151-235307C820E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {500F0DF0-D180-446D-9981-BC320C17DC7A}
EndGlobalSection
EndGlobal