Commit 3e6c8e81 authored by Laurent Le Brun's avatar Laurent Le Brun
Browse files

Add proper testing using OpenTK

Test works as follow:
- compile input file
- minify it
- check the output can still compile

We don't test the behavior of the shader, so it's not perfect. But this
catches obvious bugs (e.g. bad renaming, syntax errors, type errors).
parent 9c0f6218
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>cf735cb3-7698-41da-9e91-69d0057087cb</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Checker</RootNamespace>
<AssemblyName>Checker</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<Name>Checker</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Debug\Checker.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Release\Checker.XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="OpenTK.dll.config" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="OpenTK">
<HintPath>..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shader Minifier.fsproj">
<Name>Shader Minifier</Name>
<Project>{059c6af3-1877-4698-be34-bf7eb55d060a}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
open OpenTK.Graphics.OpenGL
open System
open System.IO
let initOpenTK () =
// OpenTK requires a GameWindow
let _ = new OpenTK.GameWindow()
()
let testCompile content =
let fragmentShader = GL.CreateShader(ShaderType.FragmentShader)
GL.ShaderSource(fragmentShader, content)
GL.CompileShader(fragmentShader)
let info = GL.GetShaderInfoLog(fragmentShader)
GL.DeleteShader(fragmentShader)
if info = "" then
true
else
printfn "compilation failed: %s" info
false
let minify content =
Ast.targetOutput <- Ast.Text
content |> main.minify "input" |> Printer.print
let check (file: string) =
try
let content = (new StreamReader(file)).ReadToEnd()
if not (testCompile content) then
printfn "Invalid input file '%s'" file
false
else
let minified = minify content + "\n"
if not (testCompile minified) then
printfn "Minification broke the file '%s'" file
printfn "%s" minified
false
else
printfn "Success: %s" file
true
with :? IO.FileNotFoundException as e ->
printfn "%A" e
false
let inputs = [
@"..\..\..\tests\unit\blocks.frag"
@"..\..\..\tests\unit\hexa.frag"
@"..\..\..\tests\unit\inline.frag"
@"..\..\..\tests\unit\keyword_prefix.frag"
@"..\..\..\tests\unit\commas.frag"
@"..\..\..\tests\unit\numbers.frag"
@"..\..\..\tests\unit\array.frag"
]
[<EntryPoint>]
let main argv =
initOpenTK()
let mutable failures = 0
for f in inputs do
if not (check f) then
failures <- failures + 1
if failures = 0 then
printfn "All good."
0
else
printfn "%d failures." failures
1
\ No newline at end of file
......@@ -23,8 +23,8 @@
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<StartArguments>
</StartArguments>
<StartArguments>-o "" ../../tests\unit\commas.frag --smoothstep</StartArguments>
<OtherFlags>--warnon:1182</OtherFlags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -33,7 +33,7 @@
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<StartArguments>-o "" ../../tests\unit\smoothstep.frag --smoothstep</StartArguments>
<StartArguments>-o "" ../../tests\unit\empty_block.frag --smoothstep</StartArguments>
<OtherFlags>--standalone</OtherFlags>
</PropertyGroup>
<Choose>
......@@ -60,6 +60,8 @@
<None Include="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="OpenTK.dll.config" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FParsec">
......
......@@ -5,6 +5,11 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Shader Minifier", "Shader Minifier.fsproj", "{059C6AF3-1877-4698-BE34-BF7EB55D060A}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Checker", "Checker\Checker.fsproj", "{CF735CB3-7698-41DA-9E91-69D0057087CB}"
ProjectSection(ProjectDependencies) = postProject
{059C6AF3-1877-4698-BE34-BF7EB55D060A} = {059C6AF3-1877-4698-BE34-BF7EB55D060A}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -15,6 +20,10 @@ Global
{059C6AF3-1877-4698-BE34-BF7EB55D060A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{059C6AF3-1877-4698-BE34-BF7EB55D060A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{059C6AF3-1877-4698-BE34-BF7EB55D060A}.Release|Any CPU.Build.0 = Release|Any CPU
{CF735CB3-7698-41DA-9E91-69D0057087CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF735CB3-7698-41DA-9E91-69D0057087CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF735CB3-7698-41DA-9E91-69D0057087CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF735CB3-7698-41DA-9E91-69D0057087CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment