Skip to content

Commit 804579d

Browse files
authored
CSharpMath.Ios.Tests (#133)
* 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
1 parent 46e7a7a commit 804579d

File tree

15 files changed

+516
-15
lines changed

15 files changed

+516
-15
lines changed

.github/workflows/Build all projects.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- name: Build
2626
run: msbuild CSharpMath.sln /p:Configuration=Release
2727
- uses: actions/upload-artifact@v2
28+
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
2829
with:
2930
name: NuGet packages
3031
path: .nupkgs/

.github/workflows/Test all projects.yml

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22

33
on: [push, pull_request]
44
jobs:
5-
all_projects:
5+
Core:
66
runs-on: ${{ matrix.os }}
77
strategy:
88
matrix:
@@ -47,3 +47,97 @@ jobs:
4747
dotnet add "$p" package GitHubActionsTestLogger
4848
dotnet test "$p" -c Release -l GitHubActions
4949
done
50+
- uses: actions/upload-artifact@v2
51+
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
52+
with:
53+
name: CSharpMath.Rendering.Tests results
54+
path: CSharpMath.Rendering.Tests/*/*.png
55+
Ios:
56+
runs-on: macos-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
with:
60+
submodules: 'recursive'
61+
- run: nuget restore CSharpMath.sln
62+
- run: msbuild CSharpMath.Ios.Tests
63+
- name: Run tests
64+
env:
65+
IOS_SIM_NAME: iPhone 11 # https://github.com/actions/virtual-environments/blob/master/images/macos/macos-10.15-Readme.md#installed-simulators
66+
BUNDLE_IDENTIFIER: CSharpMath.Ios.Unit-Tests # Located inside CSharpMath.Ios.Tests Info.plist file
67+
APP_PATH: CSharpMath.Ios.Tests/bin/iPhoneSimulator/Debug/CSharpMath.Ios.Tests.app
68+
run: |
69+
# This script is a heavily modified version of https://gist.github.com/jerrymarino/1f9eb6a06c423f9744ea297d80193a9b
70+
71+
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`
72+
SIMULATOR_PATH='/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator'
73+
74+
# run_ios_sim builds and runs an iOS app on the simulator
75+
#
76+
# It is designed to replicate the behavior of "Run" in Xcode and assumes basic
77+
# xcodebuild usage.
78+
#
79+
# USAGE:
80+
# export IOS_SIM_UDID=342F9A20-DF48-41A9-BE60-C6B35F47E97F; \
81+
# export BUNDLE_IDENTIFIER=a.Some; \
82+
# export APP_PATH=$PWD/Build/Debug-iphonesimulator/$APP_NAME.app \
83+
# /path/to/run_ios_sim.sh
84+
#
85+
# Note that the UDID must match a device where runtime is installed See
86+
# available devices with "simctl list"
87+
#
88+
# Tested on Xcode 8.3.1 a few times
89+
# Author: Jerry Marino - @jerrymarino
90+
91+
APP_NAME=`echo ""${APP_PATH##*/}"" | cut -d'.' -f1`
92+
93+
echo "Running sim for $APP_NAME - $BUNDLE_IDENTIFIER"
94+
95+
# If the booted simulator does not match, then we need to restart it. Expect an
96+
# output list of the form
97+
# "Phone: iPhone 7 Plus (342F9A20-DF48-41A9-BE60-C6B35F47E97F) (Booted)"
98+
BOOTED_UDID=`xcrun simctl list | grep Booted | perl -pe 's/(.*\()(.*)\)+ (.*)/\2/' | sed -n 1p`
99+
if [[ $BOOTED_UDID != $IOS_SIM_UDID ]]; then
100+
killall Simulator || true # Ignore error code 1: No matching process has been found
101+
else
102+
# FIXME: We don't need to do this for all cases and
103+
# it is slow
104+
killall Simulator || true # Ignore error code 1: No matching process has been found
105+
fi
106+
107+
# Open the simulator
108+
open -a "$SIMULATOR_PATH" --args -CurrentDeviceUDID $IOS_SIM_UDID
109+
110+
# Wait until there is a device booted
111+
112+
function booted_sim_ct() {
113+
echo `xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g'`
114+
}
115+
116+
while [ `booted_sim_ct` -lt 1 ]
117+
do
118+
sleep 1
119+
done
120+
121+
echo "Installing app at path $APP_PATH"
122+
xcrun simctl install booted $APP_PATH
123+
124+
# Launch the app program into the booted sim
125+
TESTS_OUTPUT=`xcrun simctl launch --console booted "$BUNDLE_IDENTIFIER" 2>&1`
126+
# 2>&1 means "redirect stderr to stdout": https://stackoverflow.com/a/818284/5429648
127+
128+
echo "$TESTS_OUTPUT"
129+
130+
# Move artifacts (generated pictures) to a known path for uploading
131+
TESTS_ARTIFACTS="`xcrun simctl get_app_container booted $BUNDLE_IDENTIFIER data`/Documents/*"
132+
mkdir -p /tmp/tests_artifacts
133+
mv $TESTS_ARTIFACTS /tmp/tests_artifacts # We don't put $TESTS_ARTIFACTS in double quotes because we need path expansion
134+
135+
# We fail this workflow if the debug output contains [FAIL] (i.e. a test has failed).
136+
if [[ "$TESTS_OUTPUT" == *"[FAIL]"* ]]
137+
then exit 1
138+
fi
139+
- uses: actions/upload-artifact@v2
140+
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
141+
with:
142+
name: CSharpMath.Ios.Tests Results
143+
path: /tmp/tests_artifacts

CSharpMath.Apple/AppleMathView.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
namespace CSharpMath.Apple {
2020
public class AppleMathView : NView {
2121
public string? ErrorMessage { get; set; }
22-
private IDisplay<TFont, TGlyph> _displayList =
23-
new Display.Displays.ListDisplay<TFont, TGlyph>(Array.Empty<IDisplay<TFont, TGlyph>>());
22+
private IDisplay<TFont, TGlyph>? _displayList = null;
2423
public float FontSize { get; set; } = 20f;
2524
public ColumnAlignment TextAlignment { get; set; } = ColumnAlignment.Left;
2625
public NContentInsets ContentInsets { get; set; }
@@ -71,7 +70,7 @@ public override CGSize SizeThatFits(CGSize size) {
7170
return r;
7271
}
7372
public override void LayoutSubviews() {
74-
if (_mathList != null) {
73+
if (_mathList != null && _displayList != null) {
7574
float displayWidth = _displayList.Width;
7675
var textX = TextAlignment switch
7776
{
@@ -95,7 +94,7 @@ public override void LayoutSubviews() {
9594
public override void Draw(CGRect rect) {
9695
base.Draw(rect);
9796
var cgContext = UIGraphics.GetCurrentContext();
98-
if (_mathList != null) {
97+
if (_mathList != null && _displayList != null) {
9998
cgContext.SaveState();
10099
cgContext.SetStrokeColor(TextColor.CGColor);
101100
cgContext.SetFillColor(TextColor.CGColor);

CSharpMath.Ios.Example/IosMathViewController.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
namespace CSharpMath.Ios.Example {
44
public class IosMathViewController : UIViewController {
55
public override void ViewDidLoad() {
6-
View.BackgroundColor = UIColor.White;
7-
var latexView = IosMathLabels.MathView(Rendering.Tests.TestRenderingMathData.IntegralColorBoxCorrect, 50); // WJWJWJ latex here
8-
latexView.ContentInsets = new UIEdgeInsets(10, 10, 10, 10);
9-
var size = latexView.SizeThatFits(new CoreGraphics.CGSize(370, 280));
10-
latexView.Frame = new CoreGraphics.CGRect(0, 40, size.Width, size.Height);
11-
View.Add(latexView);
6+
var scrollView = new UIScrollView { BackgroundColor = UIColor.White, ScrollEnabled = true };
7+
System.nfloat y = 0, w = 0;
8+
foreach (var latex in Rendering.Tests.TestRenderingMathData.AllConstants.Values) {
9+
var latexView = IosMathLabels.MathView(latex, 50); // WJWJWJ latex here
10+
var size = latexView.SizeThatFits(new CoreGraphics.CGSize(370, 280));
11+
latexView.Frame = new CoreGraphics.CGRect(0, y, size.Width, size.Height);
12+
scrollView.Add(latexView);
13+
y += size.Height;
14+
w = size.Width > w ? size.Width : w;
15+
y += 10;
16+
}
17+
scrollView.ContentSize = new CoreGraphics.CGSize(w, y);
18+
View = scrollView;
1219
}
1320
}
1421
}

CSharpMath.Ios.Tests/AppDelegate.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Foundation;
6+
using UIKit;
7+
8+
using Xunit.Runner;
9+
using Xunit.Sdk;
10+
11+
12+
namespace CSharpMath.Ios.Tests {
13+
// The UIApplicationDelegate for the application. This class is responsible for launching the
14+
// User Interface of the application, as well as listening (and optionally responding) to
15+
// application events from iOS.
16+
[Register("AppDelegate")]
17+
public partial class AppDelegate : RunnerAppDelegate {
18+
//
19+
// This method is invoked when the application has loaded and is ready to run. In this
20+
// method you should instantiate the window, load the UI into it and then make the window
21+
// visible.
22+
//
23+
// You have 17 seconds to return from this method, or iOS will terminate your application.
24+
//
25+
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
26+
27+
// We need this to ensure the execution assembly is part of the app bundle
28+
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
29+
30+
31+
// tests can be inside the main assembly
32+
AddTestAssembly(Assembly.GetExecutingAssembly());
33+
// otherwise you need to ensure that the test assemblies will
34+
// become part of the app bundle
35+
// AddTestAssembly(typeof(PortableTests).Assembly);
36+
37+
// start running the test suites as soon as the application is loaded
38+
AutoStart = true;
39+
// crash the application (to ensure it's ended) and return to springboard
40+
#if CI
41+
TerminateAfterExecution = true;
42+
#endif
43+
return base.FinishedLaunching(app, options);
44+
}
45+
}
46+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
6+
<ProjectGuid>{30C91103-12E5-47AE-85FE-41B0218A8997}</ProjectGuid>
7+
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>CSharpMath.Ios.Tests</RootNamespace>
10+
<AssemblyName>CSharpMath.Ios.Tests</AssemblyName>
11+
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
14+
<DebugSymbols>true</DebugSymbols>
15+
<DebugType>full</DebugType>
16+
<Optimize>false</Optimize>
17+
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
18+
<DefineConstants>DEBUG;</DefineConstants>
19+
<ErrorReport>prompt</ErrorReport>
20+
<WarningLevel>4</WarningLevel>
21+
<CodesignKey>iPhone Developer</CodesignKey>
22+
<MtouchDebug>true</MtouchDebug>
23+
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
24+
<MtouchFastDev>true</MtouchFastDev>
25+
<IOSDebuggerPort>23322</IOSDebuggerPort>
26+
<MtouchLink>None</MtouchLink>
27+
<MtouchArch>x86_64</MtouchArch>
28+
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
29+
<DeviceSpecificBuild>false</DeviceSpecificBuild>
30+
<MtouchVerbosity>
31+
</MtouchVerbosity>
32+
<NoWarn>
33+
</NoWarn>
34+
<LangVersion>Default</LangVersion>
35+
<Nullable>
36+
</Nullable>
37+
</PropertyGroup>
38+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
39+
<DebugType>pdbonly</DebugType>
40+
<Optimize>true</Optimize>
41+
<OutputPath>bin\iPhone\Release</OutputPath>
42+
<DefineConstants>
43+
</DefineConstants>
44+
<ErrorReport>prompt</ErrorReport>
45+
<WarningLevel>4</WarningLevel>
46+
<CodesignKey>iPhone Developer</CodesignKey>
47+
<MtouchUseLlvm>true</MtouchUseLlvm>
48+
<MtouchFloat32>true</MtouchFloat32>
49+
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
50+
<MtouchLink>SdkOnly</MtouchLink>
51+
<MtouchArch>ARM64</MtouchArch>
52+
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
53+
<MtouchVerbosity>
54+
</MtouchVerbosity>
55+
<NoWarn>
56+
</NoWarn>
57+
<LangVersion>Default</LangVersion>
58+
<Nullable>
59+
</Nullable>
60+
</PropertyGroup>
61+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
62+
<DebugType>pdbonly</DebugType>
63+
<Optimize>true</Optimize>
64+
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
65+
<DefineConstants>
66+
</DefineConstants>
67+
<ErrorReport>prompt</ErrorReport>
68+
<WarningLevel>4</WarningLevel>
69+
<CodesignKey>iPhone Developer</CodesignKey>
70+
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
71+
<MtouchLink>None</MtouchLink>
72+
<MtouchArch>x86_64</MtouchArch>
73+
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
74+
<MtouchVerbosity>
75+
</MtouchVerbosity>
76+
<NoWarn>
77+
</NoWarn>
78+
<LangVersion>Default</LangVersion>
79+
<Nullable>
80+
</Nullable>
81+
</PropertyGroup>
82+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
83+
<DebugSymbols>true</DebugSymbols>
84+
<DebugType>full</DebugType>
85+
<Optimize>false</Optimize>
86+
<OutputPath>bin\iPhone\Debug</OutputPath>
87+
<DefineConstants>DEBUG;</DefineConstants>
88+
<ErrorReport>prompt</ErrorReport>
89+
<WarningLevel>4</WarningLevel>
90+
<CodesignKey>iPhone Developer</CodesignKey>
91+
<DeviceSpecificBuild>true</DeviceSpecificBuild>
92+
<MtouchDebug>true</MtouchDebug>
93+
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
94+
<MtouchFastDev>true</MtouchFastDev>
95+
<MtouchFloat32>true</MtouchFloat32>
96+
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
97+
<IOSDebuggerPort>41866</IOSDebuggerPort>
98+
<MtouchLink>SdkOnly</MtouchLink>
99+
<MtouchArch>ARM64</MtouchArch>
100+
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
101+
<MtouchVerbosity>
102+
</MtouchVerbosity>
103+
<NoWarn>
104+
</NoWarn>
105+
<LangVersion>Default</LangVersion>
106+
<Nullable>
107+
</Nullable>
108+
</PropertyGroup>
109+
<PropertyGroup Condition="!$([System.String]::IsNullOrEmpty($(CI))) And $(CI)">
110+
<DefineConstants>$(DefineConstants);CI</DefineConstants>
111+
</PropertyGroup>
112+
<ItemGroup>
113+
<Reference Include="System" />
114+
<Reference Include="System.Xml" />
115+
<Reference Include="System.Core" />
116+
<Reference Include="Xamarin.iOS" />
117+
<PackageReference Include="xunit" Version="2.4.1" />
118+
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
119+
</ItemGroup>
120+
<ItemGroup>
121+
<InterfaceDefinition Include="LaunchScreen.storyboard" />
122+
</ItemGroup>
123+
<ItemGroup>
124+
<None Include="Info.plist" />
125+
<None Include="Entitlements.plist" />
126+
</ItemGroup>
127+
<ItemGroup>
128+
<Compile Include="Main.cs" />
129+
<Compile Include="AppDelegate.cs" />
130+
<Compile Include="Tests.cs" />
131+
<Compile Include="..\CSharpMath.Rendering.Tests\TestRenderingMathData.cs">
132+
<Link>TestRenderingMathData.cs</Link>
133+
</Compile>
134+
<Compile Include="..\CSharpMath.Rendering.Tests\TestRenderingSharedData.cs">
135+
<Link>TestRenderingSharedData.cs</Link>
136+
</Compile>
137+
<EmbeddedResource Include="..\CSharpMath.Rendering.Tests\MathDisplay\*" Exclude="..\CSharpMath.Rendering.Tests\MathDisplay\*.*.*" Link="MathDisplay\%(RecursiveDir)%(Filename)%(Extension)" />
138+
<EmbeddedResource Include="..\CSharpMath.Rendering.Tests\MathInline\*" Exclude="..\CSharpMath.Rendering.Tests\MathInline\*.*.*" Link="MathInline\%(RecursiveDir)%(Filename)%(Extension)" />
139+
</ItemGroup>
140+
<ItemGroup>
141+
<ProjectReference Include="..\CSharpMath\CSharpMath.csproj">
142+
<Project>{5157367B-F03E-4ACB-83A1-0DE414A3BFCA}</Project>
143+
<Name>CSharpMath</Name>
144+
</ProjectReference>
145+
<ProjectReference Include="..\CSharpMath.Ios\CSharpMath.Ios.csproj">
146+
<Project>{11D4E6C7-C8E2-449C-A1E7-18BBBCE4E6F3}</Project>
147+
<Name>CSharpMath.Ios</Name>
148+
</ProjectReference>
149+
</ItemGroup>
150+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
151+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
</dict>
6+
</plist>

0 commit comments

Comments
 (0)