Skip to content

Commit

Permalink
CSharpMath.Ios.Tests (#133)
Browse files Browse the repository at this point in the history
* CSharpMath.Ios.Tests

* Create Test CSharpMath.Ios.yml

* Update Test CSharpMath.Ios.yml

* Update Test CSharpMath.Ios.yml

* Update Test CSharpMath.Ios.yml

* Run app?

* Update Test CSharpMath.Ios.yml

* Update Test CSharpMath.Ios.yml

* Visual Studio automatic changes

* Fix AngouriVersion

* Try correct UDID

* xUnit > NUnit

* Imgur?

* Screenshots instead of Imgur

* Updates from https://github.community/t/unable-to-find-application-named-simulator/118331: Thanks @Yanjingzhu!

* Whoops wrong name

* killall does not accept paths

* Ignore killall errors

* Simplify waiting for PID logic

* Pass tests

* wait

* If CI Terminate

* Simplify newest_related_process

* No debugger?

* Limit pgrep to LAUNCH_SHELL_PID

* Quote variable

* Wait for process correctly

* Enable debugger again

* Write Debug.WriteLine to StdErr

* Fix

* Move it even before

* No debugger

* Launch!!

* Remove DEBUGGER_ENABLED

* Simplify more!

* Go fail some tests

* Update Test CSharpMath.Ios.yml

* Delete wrong comments

* Unquote?

* Quote correctly

* pbcopy-pbpaste

* Back to using variables

* Delete Test CSharpMath.Ios.yml

* Update Test all projects.yml

* Fix names

* Upload artifacts

* Pass tests

* Update path

* Fix image saving

* Run even when failed

* Run even when previous step failed

* Exit last

* Clarify [FAIL]

* What about no star

* Ahhh fine

* Simplify project file

* Fix * -> /

* Fix * -> /

* Fix compile items

* Add project to graph

* Reference CSharpMath
  • Loading branch information
Happypig375 authored Jun 19, 2020
1 parent 46e7a7a commit 804579d
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Build all projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: Build
run: msbuild CSharpMath.sln /p:Configuration=Release
- uses: actions/upload-artifact@v2
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
with:
name: NuGet packages
path: .nupkgs/
Expand Down
96 changes: 95 additions & 1 deletion .github/workflows/Test all projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on: [push, pull_request]
jobs:
all_projects:
Core:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -47,3 +47,97 @@ jobs:
dotnet add "$p" package GitHubActionsTestLogger
dotnet test "$p" -c Release -l GitHubActions
done
- uses: actions/upload-artifact@v2
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
with:
name: CSharpMath.Rendering.Tests results
path: CSharpMath.Rendering.Tests/*/*.png
Ios:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- run: nuget restore CSharpMath.sln
- run: msbuild CSharpMath.Ios.Tests
- name: Run tests
env:
IOS_SIM_NAME: iPhone 11 # https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#installed-simulators
BUNDLE_IDENTIFIER: CSharpMath.Ios.Unit-Tests # Located inside CSharpMath.Ios.Tests Info.plist file
APP_PATH: CSharpMath.Ios.Tests/bin/iPhoneSimulator/Debug/CSharpMath.Ios.Tests.app
run: |
# This script is a heavily modified version of https://gist.github.com/jerrymarino/1f9eb6a06c423f9744ea297d80193a9b
IOS_SIM_UDID=`xcrun simctl list | grep -w "$IOS_SIM_NAME" | awk 'match($0, /\(([-0-9A-F]+)\)/) { print substr( $0, RSTART + 1, RLENGTH - 2 )}' | head -1`
SIMULATOR_PATH='/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator'
# run_ios_sim builds and runs an iOS app on the simulator
#
# It is designed to replicate the behavior of "Run" in Xcode and assumes basic
# xcodebuild usage.
#
# USAGE:
# export IOS_SIM_UDID=342F9A20-DF48-41A9-BE60-C6B35F47E97F; \
# export BUNDLE_IDENTIFIER=a.Some; \
# export APP_PATH=$PWD/Build/Debug-iphonesimulator/$APP_NAME.app \
# /path/to/run_ios_sim.sh
#
# Note that the UDID must match a device where runtime is installed See
# available devices with "simctl list"
#
# Tested on Xcode 8.3.1 a few times
# Author: Jerry Marino - @jerrymarino
APP_NAME=`echo ""${APP_PATH##*/}"" | cut -d'.' -f1`
echo "Running sim for $APP_NAME - $BUNDLE_IDENTIFIER"
# If the booted simulator does not match, then we need to restart it. Expect an
# output list of the form
# "Phone: iPhone 7 Plus (342F9A20-DF48-41A9-BE60-C6B35F47E97F) (Booted)"
BOOTED_UDID=`xcrun simctl list | grep Booted | perl -pe 's/(.*\()(.*)\)+ (.*)/\2/' | sed -n 1p`
if [[ $BOOTED_UDID != $IOS_SIM_UDID ]]; then
killall Simulator || true # Ignore error code 1: No matching process has been found
else
# FIXME: We don't need to do this for all cases and
# it is slow
killall Simulator || true # Ignore error code 1: No matching process has been found
fi
# Open the simulator
open -a "$SIMULATOR_PATH" --args -CurrentDeviceUDID $IOS_SIM_UDID
# Wait until there is a device booted
function booted_sim_ct() {
echo `xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g'`
}
while [ `booted_sim_ct` -lt 1 ]
do
sleep 1
done
echo "Installing app at path $APP_PATH"
xcrun simctl install booted $APP_PATH
# Launch the app program into the booted sim
TESTS_OUTPUT=`xcrun simctl launch --console booted "$BUNDLE_IDENTIFIER" 2>&1`
# 2>&1 means "redirect stderr to stdout": https://stackoverflow.com/a/818284/5429648
echo "$TESTS_OUTPUT"
# Move artifacts (generated pictures) to a known path for uploading
TESTS_ARTIFACTS="`xcrun simctl get_app_container booted $BUNDLE_IDENTIFIER data`/Documents/*"
mkdir -p /tmp/tests_artifacts
mv $TESTS_ARTIFACTS /tmp/tests_artifacts # We don't put $TESTS_ARTIFACTS in double quotes because we need path expansion
# We fail this workflow if the debug output contains [FAIL] (i.e. a test has failed).
if [[ "$TESTS_OUTPUT" == *"[FAIL]"* ]]
then exit 1
fi
- uses: actions/upload-artifact@v2
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
with:
name: CSharpMath.Ios.Tests Results
path: /tmp/tests_artifacts
7 changes: 3 additions & 4 deletions CSharpMath.Apple/AppleMathView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
namespace CSharpMath.Apple {
public class AppleMathView : NView {
public string? ErrorMessage { get; set; }
private IDisplay<TFont, TGlyph> _displayList =
new Display.Displays.ListDisplay<TFont, TGlyph>(Array.Empty<IDisplay<TFont, TGlyph>>());
private IDisplay<TFont, TGlyph>? _displayList = null;
public float FontSize { get; set; } = 20f;
public ColumnAlignment TextAlignment { get; set; } = ColumnAlignment.Left;
public NContentInsets ContentInsets { get; set; }
Expand Down Expand Up @@ -71,7 +70,7 @@ public override CGSize SizeThatFits(CGSize size) {
return r;
}
public override void LayoutSubviews() {
if (_mathList != null) {
if (_mathList != null && _displayList != null) {
float displayWidth = _displayList.Width;
var textX = TextAlignment switch
{
Expand All @@ -95,7 +94,7 @@ public override void LayoutSubviews() {
public override void Draw(CGRect rect) {
base.Draw(rect);
var cgContext = UIGraphics.GetCurrentContext();
if (_mathList != null) {
if (_mathList != null && _displayList != null) {
cgContext.SaveState();
cgContext.SetStrokeColor(TextColor.CGColor);
cgContext.SetFillColor(TextColor.CGColor);
Expand Down
19 changes: 13 additions & 6 deletions CSharpMath.Ios.Example/IosMathViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
namespace CSharpMath.Ios.Example {
public class IosMathViewController : UIViewController {
public override void ViewDidLoad() {
View.BackgroundColor = UIColor.White;
var latexView = IosMathLabels.MathView(Rendering.Tests.TestRenderingMathData.IntegralColorBoxCorrect, 50); // WJWJWJ latex here
latexView.ContentInsets = new UIEdgeInsets(10, 10, 10, 10);
var size = latexView.SizeThatFits(new CoreGraphics.CGSize(370, 280));
latexView.Frame = new CoreGraphics.CGRect(0, 40, size.Width, size.Height);
View.Add(latexView);
var scrollView = new UIScrollView { BackgroundColor = UIColor.White, ScrollEnabled = true };
System.nfloat y = 0, w = 0;
foreach (var latex in Rendering.Tests.TestRenderingMathData.AllConstants.Values) {
var latexView = IosMathLabels.MathView(latex, 50); // WJWJWJ latex here
var size = latexView.SizeThatFits(new CoreGraphics.CGSize(370, 280));
latexView.Frame = new CoreGraphics.CGRect(0, y, size.Width, size.Height);
scrollView.Add(latexView);
y += size.Height;
w = size.Width > w ? size.Width : w;
y += 10;
}
scrollView.ContentSize = new CoreGraphics.CGSize(w, y);
View = scrollView;
}
}
}
46 changes: 46 additions & 0 deletions CSharpMath.Ios.Tests/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Foundation;
using UIKit;

using Xunit.Runner;
using Xunit.Sdk;


namespace CSharpMath.Ios.Tests {
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : RunnerAppDelegate {
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {

// We need this to ensure the execution assembly is part of the app bundle
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);


// tests can be inside the main assembly
AddTestAssembly(Assembly.GetExecutingAssembly());
// otherwise you need to ensure that the test assemblies will
// become part of the app bundle
// AddTestAssembly(typeof(PortableTests).Assembly);

// start running the test suites as soon as the application is loaded
AutoStart = true;
// crash the application (to ensure it's ended) and return to springboard
#if CI
TerminateAfterExecution = true;
#endif
return base.FinishedLaunching(app, options);
}
}
}
151 changes: 151 additions & 0 deletions CSharpMath.Ios.Tests/CSharpMath.Ios.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProjectGuid>{30C91103-12E5-47AE-85FE-41B0218A8997}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>CSharpMath.Ios.Tests</RootNamespace>
<AssemblyName>CSharpMath.Ios.Tests</AssemblyName>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
<IOSDebuggerPort>23322</IOSDebuggerPort>
<MtouchLink>None</MtouchLink>
<MtouchArch>x86_64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
<MtouchVerbosity>
</MtouchVerbosity>
<NoWarn>
</NoWarn>
<LangVersion>Default</LangVersion>
<Nullable>
</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchFloat32>true</MtouchFloat32>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchArch>ARM64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity>
</MtouchVerbosity>
<NoWarn>
</NoWarn>
<LangVersion>Default</LangVersion>
<Nullable>
</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>None</MtouchLink>
<MtouchArch>x86_64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity>
</MtouchVerbosity>
<NoWarn>
</NoWarn>
<LangVersion>Default</LangVersion>
<Nullable>
</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<DeviceSpecificBuild>true</DeviceSpecificBuild>
<MtouchDebug>true</MtouchDebug>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchFastDev>true</MtouchFastDev>
<MtouchFloat32>true</MtouchFloat32>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<IOSDebuggerPort>41866</IOSDebuggerPort>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchArch>ARM64</MtouchArch>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<MtouchVerbosity>
</MtouchVerbosity>
<NoWarn>
</NoWarn>
<LangVersion>Default</LangVersion>
<Nullable>
</Nullable>
</PropertyGroup>
<PropertyGroup Condition="!$([System.String]::IsNullOrEmpty($(CI))) And $(CI)">
<DefineConstants>$(DefineConstants);CI</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="LaunchScreen.storyboard" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Entitlements.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="Tests.cs" />
<Compile Include="..\CSharpMath.Rendering.Tests\TestRenderingMathData.cs">
<Link>TestRenderingMathData.cs</Link>
</Compile>
<Compile Include="..\CSharpMath.Rendering.Tests\TestRenderingSharedData.cs">
<Link>TestRenderingSharedData.cs</Link>
</Compile>
<EmbeddedResource Include="..\CSharpMath.Rendering.Tests\MathDisplay\*" Exclude="..\CSharpMath.Rendering.Tests\MathDisplay\*.*.*" Link="MathDisplay\%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="..\CSharpMath.Rendering.Tests\MathInline\*" Exclude="..\CSharpMath.Rendering.Tests\MathInline\*.*.*" Link="MathInline\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpMath\CSharpMath.csproj">
<Project>{5157367B-F03E-4ACB-83A1-0DE414A3BFCA}</Project>
<Name>CSharpMath</Name>
</ProjectReference>
<ProjectReference Include="..\CSharpMath.Ios\CSharpMath.Ios.csproj">
<Project>{11D4E6C7-C8E2-449C-A1E7-18BBBCE4E6F3}</Project>
<Name>CSharpMath.Ios</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions CSharpMath.Ios.Tests/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
Loading

0 comments on commit 804579d

Please sign in to comment.