Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharpMath.Ios.Tests #133

Merged
merged 61 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
524bd56
CSharpMath.Ios.Tests
Happypig375 Jun 16, 2020
b94f47f
Create Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
c0854da
Update Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
de81583
Update Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
73d5d9c
Update Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
ae1d860
Run app?
Happypig375 Jun 16, 2020
fe8cb40
Update Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
476e5c3
Update Test CSharpMath.Ios.yml
Happypig375 Jun 16, 2020
1248807
Visual Studio automatic changes
Happypig375 Jun 17, 2020
5d85d93
Fix AngouriVersion
Happypig375 Jun 17, 2020
b39e4c0
Try correct UDID
Happypig375 Jun 17, 2020
29d78ad
xUnit > NUnit
Happypig375 Jun 17, 2020
d3268f3
Imgur?
Happypig375 Jun 17, 2020
bea81c8
Screenshots instead of Imgur
Happypig375 Jun 17, 2020
2a8cda8
Updates from https://github.community/t/unable-to-find-application-na…
Happypig375 Jun 18, 2020
2eda59a
Whoops wrong name
Happypig375 Jun 18, 2020
ae19b71
killall does not accept paths
Happypig375 Jun 18, 2020
d4e8b54
Ignore killall errors
Happypig375 Jun 18, 2020
e48963e
Simplify waiting for PID logic
Happypig375 Jun 18, 2020
945d50b
Pass tests
Happypig375 Jun 18, 2020
fbf6e78
wait
Happypig375 Jun 18, 2020
0af633b
If CI Terminate
Happypig375 Jun 18, 2020
043d461
Simplify newest_related_process
Happypig375 Jun 18, 2020
a50573c
No debugger?
Happypig375 Jun 18, 2020
938e383
Limit pgrep to LAUNCH_SHELL_PID
Happypig375 Jun 18, 2020
637bd7d
Quote variable
Happypig375 Jun 18, 2020
f696545
Wait for process correctly
Happypig375 Jun 18, 2020
dc8d8b1
Enable debugger again
Happypig375 Jun 18, 2020
c0fb54a
Write Debug.WriteLine to StdErr
Happypig375 Jun 18, 2020
9c489e4
Fix
Happypig375 Jun 18, 2020
49dcda2
Move it even before
Happypig375 Jun 18, 2020
6437fd0
No debugger
Happypig375 Jun 18, 2020
f3e65e8
Launch!!
Happypig375 Jun 18, 2020
17cbba0
Remove DEBUGGER_ENABLED
Happypig375 Jun 18, 2020
1e4521e
Simplify more!
Happypig375 Jun 18, 2020
8df86a3
Go fail some tests
Happypig375 Jun 18, 2020
00b807a
Update Test CSharpMath.Ios.yml
Happypig375 Jun 18, 2020
49381ab
Delete wrong comments
Happypig375 Jun 18, 2020
b99f610
Unquote?
Happypig375 Jun 18, 2020
0c6ac8b
Quote correctly
Happypig375 Jun 18, 2020
ae40244
pbcopy-pbpaste
Happypig375 Jun 18, 2020
15beb58
Back to using variables
Happypig375 Jun 18, 2020
5aa93ce
Delete Test CSharpMath.Ios.yml
Happypig375 Jun 19, 2020
0ad4b77
Update Test all projects.yml
Happypig375 Jun 19, 2020
c0b2d48
Fix names
Happypig375 Jun 19, 2020
6697811
Upload artifacts
Happypig375 Jun 19, 2020
b0c7406
Pass tests
Happypig375 Jun 19, 2020
ad5ee54
Update path
Happypig375 Jun 19, 2020
f287fbb
Fix image saving
Happypig375 Jun 19, 2020
0567732
Run even when failed
Happypig375 Jun 19, 2020
50076a6
Run even when previous step failed
Happypig375 Jun 19, 2020
a3131a5
Exit last
Happypig375 Jun 19, 2020
fca94da
Clarify [FAIL]
Happypig375 Jun 19, 2020
d46e5a3
What about no star
Happypig375 Jun 19, 2020
4fd5a20
Ahhh fine
Happypig375 Jun 19, 2020
a8a1813
Simplify project file
Happypig375 Jun 19, 2020
53dd3ef
Fix * -> /
Happypig375 Jun 19, 2020
807e464
Fix * -> /
Happypig375 Jun 19, 2020
7aa3a13
Fix compile items
Happypig375 Jun 19, 2020
8467cf9
Add project to graph
Happypig375 Jun 19, 2020
3e7ee18
Reference CSharpMath
Happypig375 Jun 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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