fix line endings problem (?)

pull/164/head
Aaron Trudeau 2023-06-07 02:05:27 -04:00
parent fb62d36ba1
commit 1cba302bc4
No known key found for this signature in database
GPG Key ID: 5EA8D416A3C71A20
31 changed files with 807 additions and 807 deletions

View File

@ -1,246 +1,246 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Set and display project path # Set and display project path
# #
UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH" UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH"
echo "Using project path \"$UNITY_PROJECT_PATH\"." echo "Using project path \"$UNITY_PROJECT_PATH\"."
# #
# Set and display the artifacts path # Set and display the artifacts path
# #
echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results." echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results."
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH
# #
# Set and display the coverage results path # Set and display the coverage results path
# #
echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results." echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results."
FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH
# #
# Display custom parameters # Display custom parameters
# #
echo "Using custom parameters $CUSTOM_PARAMETERS." echo "Using custom parameters $CUSTOM_PARAMETERS."
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later) # The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html # Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
# #
# Display the unity version # Display the unity version
# #
echo "Using Unity version \"$UNITY_VERSION\" to test." echo "Using Unity version \"$UNITY_VERSION\" to test."
# #
# Create an empty project for testing if in package mode # Create an empty project for testing if in package mode
# #
if [ "$PACKAGE_MODE" = "true" ]; then if [ "$PACKAGE_MODE" = "true" ]; then
echo "Running tests on a Unity package rather than a Unity project." echo "Running tests on a Unity package rather than a Unity project."
if ! command -v jq &> /dev/null if ! command -v jq &> /dev/null
then then
echo "jq could not be found. This is required for package mode, and is likely the result of using a custom Docker image. Please use the default image or install jq to your custom image." echo "jq could not be found. This is required for package mode, and is likely the result of using a custom Docker image. Please use the default image or install jq to your custom image."
exit exit
fi fi
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Package Folder #" echo "# Package Folder #"
echo "###########################" echo "###########################"
echo "" echo ""
ls -la "$UNITY_PROJECT_PATH" ls -la "$UNITY_PROJECT_PATH"
echo "" echo ""
echo "Creating an empty Unity project to add the package $PACKAGE_NAME to." echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."
TEMP_PROJECT_PATH="./TempProject" TEMP_PROJECT_PATH="./TempProject"
unity-editor \ unity-editor \
-batchmode \ -batchmode \
-createProject "$TEMP_PROJECT_PATH" \ -createProject "$TEMP_PROJECT_PATH" \
-quit -quit
# use jq to add the package to the temp project through manually modifying Packages/manifest.json # use jq to add the package to the temp project through manually modifying Packages/manifest.json
echo "Adding package to the temporary project's dependencies and testables..." echo "Adding package to the temporary project's dependencies and testables..."
echo "" echo ""
PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json" PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then
echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..." echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..."
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Temp Project Folder #" echo "# Temp Project Folder #"
echo "###########################" echo "###########################"
echo "" echo ""
ls -a "$TEMP_PROJECT_PATH" ls -a "$TEMP_PROJECT_PATH"
echo "" echo ""
echo "################################" echo "################################"
echo "# Temp Project Packages Folder #" echo "# Temp Project Packages Folder #"
echo "################################" echo "################################"
echo "" echo ""
ls -a "$TEMP_PROJECT_PATH/Packages" ls -a "$TEMP_PROJECT_PATH/Packages"
exit 1 exit 1
fi fi
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH") PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
echo "$PACKAGE_MANIFEST_JSON" | \ echo "$PACKAGE_MANIFEST_JSON" | \
jq \ jq \
--arg packageName "$PACKAGE_NAME" \ --arg packageName "$PACKAGE_NAME" \
--arg projectPath "$UNITY_PROJECT_PATH" \ --arg projectPath "$UNITY_PROJECT_PATH" \
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \ '.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
> "$PACKAGE_MANIFEST_PATH" > "$PACKAGE_MANIFEST_PATH"
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH" UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
fi fi
# #
# Overall info # Overall info
# #
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Artifacts folder #" echo "# Artifacts folder #"
echo "###########################" echo "###########################"
echo "" echo ""
echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist." echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist."
mkdir -p $FULL_ARTIFACTS_PATH mkdir -p $FULL_ARTIFACTS_PATH
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Project directory #" echo "# Project directory #"
echo "###########################" echo "###########################"
echo "" echo ""
ls -alh $UNITY_PROJECT_PATH ls -alh $UNITY_PROJECT_PATH
# #
# Testing for each platform # Testing for each platform
# #
for platform in ${TEST_PLATFORMS//;/ }; do for platform in ${TEST_PLATFORMS//;/ }; do
if [[ "$platform" == "standalone" ]]; then if [[ "$platform" == "standalone" ]]; then
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Building Standalone #" echo "# Building Standalone #"
echo "###########################" echo "###########################"
echo "" echo ""
# Create directories if they do not exist # Create directories if they do not exist
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/" mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/" mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
# Copy the scripts # Copy the scripts
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/" cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/"
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/" cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/"
# Verify recursive paths # Verify recursive paths
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/" ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/" ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/"
runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
else else
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Testing in $platform #" echo "# Testing in $platform #"
echo "###########################" echo "###########################"
echo "" echo ""
if [[ "$platform" != "COMBINE_RESULTS" ]]; then if [[ "$platform" != "COMBINE_RESULTS" ]]; then
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml" runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
else else
runTests="-quit" runTests="-quit"
fi fi
fi fi
unity-editor \ unity-editor \
-batchmode \ -batchmode \
-logFile "$FULL_ARTIFACTS_PATH/$platform.log" \ -logFile "$FULL_ARTIFACTS_PATH/$platform.log" \
-projectPath "$UNITY_PROJECT_PATH" \ -projectPath "$UNITY_PROJECT_PATH" \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \ -coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
$runTests \ $runTests \
-enableCodeCoverage \ -enableCodeCoverage \
-debugCodeOptimization \ -debugCodeOptimization \
-coverageOptions "$COVERAGE_OPTIONS" \ -coverageOptions "$COVERAGE_OPTIONS" \
$CUSTOM_PARAMETERS $CUSTOM_PARAMETERS
# Catch exit code # Catch exit code
TEST_EXIT_CODE=$? TEST_EXIT_CODE=$?
# Print unity log output # Print unity log output
cat "$FULL_ARTIFACTS_PATH/$platform.log" cat "$FULL_ARTIFACTS_PATH/$platform.log"
if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
echo "" echo ""
echo "###########################" echo "###########################"
echo "# Testing Standalone #" echo "# Testing Standalone #"
echo "###########################" echo "###########################"
echo "" echo ""
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player. # Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
# https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works # https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works
xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \ xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \
-batchmode \ -batchmode \
-nographics \ -nographics \
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \ -logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
-testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml" -testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml"
# Catch exit code # Catch exit code
TEST_EXIT_CODE=$? TEST_EXIT_CODE=$?
# Print player log output # Print player log output
cat "$FULL_ARTIFACTS_PATH/$platform-player.log" cat "$FULL_ARTIFACTS_PATH/$platform-player.log"
fi fi
# Display results # Display results
if [ $TEST_EXIT_CODE -eq 0 ]; then if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred"; echo "Run succeeded, no failures occurred";
elif [ $TEST_EXIT_CODE -eq 2 ]; then elif [ $TEST_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed"; echo "Run succeeded, some tests failed";
elif [ $TEST_EXIT_CODE -eq 3 ]; then elif [ $TEST_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)"; echo "Run failure (other failure)";
else else
echo "Unexpected exit code $TEST_EXIT_CODE"; echo "Unexpected exit code $TEST_EXIT_CODE";
fi fi
if [ $TEST_EXIT_CODE -ne 0 ]; then if [ $TEST_EXIT_CODE -ne 0 ]; then
TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE
fi fi
echo "" echo ""
echo "###########################" echo "###########################"
echo "# $platform Results #" echo "# $platform Results #"
echo "###########################" echo "###########################"
echo "" echo ""
if [[ "$platform" != "COMBINE_RESULTS" ]]; then if [[ "$platform" != "COMBINE_RESULTS" ]]; then
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" cat "$FULL_ARTIFACTS_PATH/$platform-results.xml"
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
fi fi
done done
# #
# Permissions # Permissions
# #
# Make a given user owner of all artifacts # Make a given user owner of all artifacts
if [[ -n "$CHOWN_FILES_TO" ]]; then if [[ -n "$CHOWN_FILES_TO" ]]; then
chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH" chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH" chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH" chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH"
fi fi
# Add read permissions for everyone to all artifacts # Add read permissions for everyone to all artifacts
chmod -R a+r "$UNITY_PROJECT_PATH" chmod -R a+r "$UNITY_PROJECT_PATH"
chmod -R a+r "$FULL_ARTIFACTS_PATH" chmod -R a+r "$FULL_ARTIFACTS_PATH"
chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH" chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH"

View File

@ -1,4 +1,4 @@
if ($null -eq ${env:GIT_PRIVATE_TOKEN}) if ($null -eq ${env:GIT_PRIVATE_TOKEN})
{ {
Write-Output "GIT_PRIVATE_TOKEN unset skipping" Write-Output "GIT_PRIVATE_TOKEN unset skipping"
} }

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -z "${GIT_PRIVATE_TOKEN}" ] if [ -z "${GIT_PRIVATE_TOKEN}" ]
then then

View File

@ -1,4 +1,4 @@
# #
# Note: Non default ignore file, as this only tests Builder script. # Note: Non default ignore file, as this only tests Builder script.
# #

View File

@ -1,4 +1,4 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import fs from 'fs'; import fs from 'fs';
class LicensingServerSetup { class LicensingServerSetup {

View File

@ -1,4 +1,4 @@
import { components } from '@octokit/openapi-types'; import { components } from '@octokit/openapi-types';
export function timeHelper(seconds: number): string { export function timeHelper(seconds: number): string {
return `${seconds.toFixed(3)}s`; return `${seconds.toFixed(3)}s`;

View File

@ -1,4 +1,4 @@
interface CommonAttributes { interface CommonAttributes {
id: string; id: string;
result: string; result: string;
asserts: string; asserts: string;

View File

@ -1,8 +1,8 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: e3a65787d84893340b9dc38af5b7c31f guid: e3a65787d84893340b9dc38af5b7c31f
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

View File

@ -1,6 +1,6 @@
{ {
"name": "fake.notarealpackage.Editor", "name": "fake.notarealpackage.Editor",
"references": [ "references": [
"fake.notarealpackage.Runtime" "fake.notarealpackage.Runtime"
] ]
} }

View File

@ -1,8 +1,8 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6c6729c46a2a6594da2ce1182420ab81 guid: 6c6729c46a2a6594da2ce1182420ab81
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

View File

@ -1,18 +1,18 @@
using System; using System;
public class BasicCounter public class BasicCounter
{ {
public const int MaxCount = 10; public const int MaxCount = 10;
public BasicCounter(int count = 0) public BasicCounter(int count = 0)
{ {
Count = count; Count = count;
} }
public void Increment() public void Increment()
{ {
Count = Math.Min(MaxCount, Count + 1); Count = Math.Min(MaxCount, Count + 1);
} }
public int Count { get; private set; } public int Count { get; private set; }
} }

View File

@ -1,17 +1,17 @@
using UnityEngine; using UnityEngine;
public class SampleComponent : MonoBehaviour public class SampleComponent : MonoBehaviour
{ {
public BasicCounter Counter; public BasicCounter Counter;
void Start() void Start()
{ {
Counter = new BasicCounter(5); Counter = new BasicCounter(5);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
Counter.Increment(); Counter.Increment();
} }
} }

View File

@ -1,18 +1,18 @@
using UnityEngine; using UnityEngine;
public class TimerComponent : MonoBehaviour public class TimerComponent : MonoBehaviour
{ {
public BasicCounter Counter = new BasicCounter(); public BasicCounter Counter = new BasicCounter();
public float Timer = 1f; public float Timer = 1f;
void Update() void Update()
{ {
Timer -= Time.deltaTime; Timer -= Time.deltaTime;
if (Timer > 0) if (Timer > 0)
return; return;
Counter.Increment(); Counter.Increment();
Timer = 1f; Timer = 1f;
} }
} }

View File

@ -1,3 +1,3 @@
{ {
"name": "fake.notarealpackage.Runtime" "name": "fake.notarealpackage.Runtime"
} }

View File

@ -1,38 +1,38 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;
namespace Tests namespace Tests
{ {
public class SampleEditModeTest public class SampleEditModeTest
{ {
[Test] [Test]
public void TestIncrement() public void TestIncrement()
{ {
// Given // Given
var counter = new BasicCounter(0); var counter = new BasicCounter(0);
// When // When
counter.Increment(); counter.Increment();
// Then // Then
Assert.AreEqual(1, counter.Count); Assert.AreEqual(1, counter.Count);
} }
[Test] [Test]
public void TestMaxCount() public void TestMaxCount()
{ {
// Given // Given
var counter = new BasicCounter(BasicCounter.MaxCount); var counter = new BasicCounter(BasicCounter.MaxCount);
// When // When
counter.Increment(); counter.Increment();
// Then // Then
Assert.AreEqual(BasicCounter.MaxCount, counter.Count); Assert.AreEqual(BasicCounter.MaxCount, counter.Count);
} }
} }
} }

View File

@ -1,14 +1,14 @@
{ {
"name": "fake.notarealpackage.EditorTests", "name": "fake.notarealpackage.EditorTests",
"references": [ "references": [
"fake.notarealpackage.Runtime", "fake.notarealpackage.Runtime",
"fake.notarealpackage.Editor" "fake.notarealpackage.Editor"
], ],
"optionalUnityReferences": [ "optionalUnityReferences": [
"TestAssemblies" "TestAssemblies"
], ],
"includePlatforms": [ "includePlatforms": [
"Editor" "Editor"
], ],
"excludePlatforms": [] "excludePlatforms": []
} }

View File

@ -1,31 +1,31 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;
namespace Tests namespace Tests
{ {
public class SampleComponentTest public class SampleComponentTest
{ {
private GameObject target; private GameObject target;
private SampleComponent component; private SampleComponent component;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
target = GameObject.Instantiate(new GameObject()); target = GameObject.Instantiate(new GameObject());
component = target.AddComponent<SampleComponent>(); component = target.AddComponent<SampleComponent>();
} }
[UnityTest] [UnityTest]
public IEnumerator TestIncrementOnUpdateAfterNextFrame() public IEnumerator TestIncrementOnUpdateAfterNextFrame()
{ {
// Save the current value, since it was updated after component Start() method called // Save the current value, since it was updated after component Start() method called
var count = component.Counter.Count; var count = component.Counter.Count;
// Skip frame and assert the new value // Skip frame and assert the new value
yield return null; yield return null;
Assert.AreEqual(count + 1, component.Counter.Count); Assert.AreEqual(count + 1, component.Counter.Count);
} }
} }
} }

View File

@ -1,42 +1,42 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine.TestTools; using UnityEngine.TestTools;
namespace Tests namespace Tests
{ {
public class SamplePlayModeTest public class SamplePlayModeTest
{ {
// A Test behaves as an ordinary method // A Test behaves as an ordinary method
[Test] [Test]
public void NewTestScriptSimplePasses() public void NewTestScriptSimplePasses()
{ {
// Given // Given
var counter = new BasicCounter(0); var counter = new BasicCounter(0);
// When // When
counter.Increment(); counter.Increment();
// Then // Then
Assert.AreEqual(1, counter.Count); Assert.AreEqual(1, counter.Count);
} }
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame. // `yield return null;` to skip a frame.
[UnityTest] [UnityTest]
public IEnumerator NewTestScriptWithEnumeratorPasses() public IEnumerator NewTestScriptWithEnumeratorPasses()
{ {
// Given // Given
var counter = new BasicCounter(3); var counter = new BasicCounter(3);
// Use the Assert class to test conditions. // Use the Assert class to test conditions.
// Use yield to skip a frame. // Use yield to skip a frame.
yield return null; yield return null;
// When // When
counter.Increment(); counter.Increment();
// Then // Then
Assert.AreEqual(4, counter.Count); Assert.AreEqual(4, counter.Count);
} }
} }
} }

View File

@ -1,66 +1,66 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;
namespace Tests namespace Tests
{ {
public class TimerComponentTest public class TimerComponentTest
{ {
private GameObject target; private GameObject target;
private TimerComponent component; private TimerComponent component;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
target = GameObject.Instantiate(new GameObject()); target = GameObject.Instantiate(new GameObject());
component = target.AddComponent<TimerComponent>(); component = target.AddComponent<TimerComponent>();
} }
[UnityTest] [UnityTest]
public IEnumerator TestIncrementAfterSomeTime() public IEnumerator TestIncrementAfterSomeTime()
{ {
// Save the current value, since it was updated after component Start() method called // Save the current value, since it was updated after component Start() method called
var count = component.Counter.Count; var count = component.Counter.Count;
// Skip frame and assert the new value // Skip frame and assert the new value
yield return null; yield return null;
Assert.AreEqual(count, component.Counter.Count); Assert.AreEqual(count, component.Counter.Count);
yield return new WaitForSeconds(1.1f); yield return new WaitForSeconds(1.1f);
Assert.AreEqual(count + 1, component.Counter.Count); Assert.AreEqual(count + 1, component.Counter.Count);
yield return new WaitForSeconds(1.1f); yield return new WaitForSeconds(1.1f);
Assert.AreEqual(count + 2, component.Counter.Count); Assert.AreEqual(count + 2, component.Counter.Count);
} }
[UnityTest] [UnityTest]
public IEnumerator TestTimeScaleIsAffectingIncrement() public IEnumerator TestTimeScaleIsAffectingIncrement()
{ {
// Save the current value, since it was updated after component Start() method called // Save the current value, since it was updated after component Start() method called
var count = component.Counter.Count; var count = component.Counter.Count;
Time.timeScale = .5f; Time.timeScale = .5f;
// Skip frame and assert the new value // Skip frame and assert the new value
yield return null; yield return null;
Assert.AreEqual(count, component.Counter.Count); Assert.AreEqual(count, component.Counter.Count);
yield return WaitForRealSeconds(1.1f); yield return WaitForRealSeconds(1.1f);
Assert.AreEqual(count, component.Counter.Count); Assert.AreEqual(count, component.Counter.Count);
yield return WaitForRealSeconds(1.1f); yield return WaitForRealSeconds(1.1f);
Assert.AreEqual(count + 1, component.Counter.Count); Assert.AreEqual(count + 1, component.Counter.Count);
} }
// Skipping time ignoring Time.scale // Skipping time ignoring Time.scale
// https://answers.unity.com/questions/301868/yield-waitforseconds-outside-of-timescale.html // https://answers.unity.com/questions/301868/yield-waitforseconds-outside-of-timescale.html
public static IEnumerator WaitForRealSeconds(float time) public static IEnumerator WaitForRealSeconds(float time)
{ {
float start = Time.realtimeSinceStartup; float start = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup < start + time) while (Time.realtimeSinceStartup < start + time)
{ {
yield return null; yield return null;
} }
} }
} }
} }

View File

@ -1,11 +1,11 @@
{ {
"name": "fake.notarealpackage.RuntimeTests", "name": "fake.notarealpackage.RuntimeTests",
"references": [ "references": [
"fake.notarealpackage.Runtime" "fake.notarealpackage.Runtime"
], ],
"optionalUnityReferences": [ "optionalUnityReferences": [
"TestAssemblies" "TestAssemblies"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [] "excludePlatforms": []
} }

View File

@ -1,7 +1,7 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4232dbd3889ab6a4393e846291288fb0 guid: 4232dbd3889ab6a4393e846291288fb0
PackageManifestImporter: PackageManifestImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

View File

@ -1,259 +1,259 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!29 &1 --- !u!29 &1
OcclusionCullingSettings: OcclusionCullingSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_OcclusionBakeSettings: m_OcclusionBakeSettings:
smallestOccluder: 5 smallestOccluder: 5
smallestHole: 0.25 smallestHole: 0.25
backfaceThreshold: 100 backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000 m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0} m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2 --- !u!104 &2
RenderSettings: RenderSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 9 serializedVersion: 9
m_Fog: 0 m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3 m_FogMode: 3
m_FogDensity: 0.01 m_FogDensity: 0.01
m_LinearFogStart: 0 m_LinearFogStart: 0
m_LinearFogEnd: 300 m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1 m_AmbientIntensity: 1
m_AmbientMode: 0 m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5 m_HaloStrength: 0.5
m_FlareStrength: 1 m_FlareStrength: 1
m_FlareFadeSpeed: 3 m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0} m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0 m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128 m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1 m_ReflectionBounces: 1
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994} m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 11 serializedVersion: 11
m_GIWorkflowMode: 0 m_GIWorkflowMode: 0
m_GISettings: m_GISettings:
serializedVersion: 2 serializedVersion: 2
m_BounceScale: 1 m_BounceScale: 1
m_IndirectOutputScale: 1 m_IndirectOutputScale: 1
m_AlbedoBoost: 1 m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1 m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0 m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1 m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1 m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings: m_LightmapEditorSettings:
serializedVersion: 10 serializedVersion: 10
m_Resolution: 2 m_Resolution: 2
m_BakeResolution: 40 m_BakeResolution: 40
m_AtlasSize: 1024 m_AtlasSize: 1024
m_AO: 0 m_AO: 0
m_AOMaxDistance: 1 m_AOMaxDistance: 1
m_CompAOExponent: 1 m_CompAOExponent: 1
m_CompAOExponentDirect: 0 m_CompAOExponentDirect: 0
m_Padding: 2 m_Padding: 2
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1 m_LightmapsBakeMode: 1
m_TextureCompression: 1 m_TextureCompression: 1
m_FinalGather: 0 m_FinalGather: 0
m_FinalGatherFiltering: 1 m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256 m_FinalGatherRayCount: 256
m_ReflectionCompression: 2 m_ReflectionCompression: 2
m_MixedBakeMode: 2 m_MixedBakeMode: 2
m_BakeBackend: 1 m_BakeBackend: 1
m_PVRSampling: 1 m_PVRSampling: 1
m_PVRDirectSampleCount: 32 m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500 m_PVRSampleCount: 500
m_PVRBounces: 2 m_PVRBounces: 2
m_PVRFilterTypeDirect: 0 m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0 m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0 m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1 m_PVRFilteringMode: 1
m_PVRCulling: 1 m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5 m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2 m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1 m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1 m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0} m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1 m_UseShadowmask: 1
--- !u!196 &4 --- !u!196 &4
NavMeshSettings: NavMeshSettings:
serializedVersion: 2 serializedVersion: 2
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_BuildSettings: m_BuildSettings:
serializedVersion: 2 serializedVersion: 2
agentTypeID: 0 agentTypeID: 0
agentRadius: 0.5 agentRadius: 0.5
agentHeight: 2 agentHeight: 2
agentSlope: 45 agentSlope: 45
agentClimb: 0.4 agentClimb: 0.4
ledgeDropHeight: 0 ledgeDropHeight: 0
maxJumpAcrossDistance: 0 maxJumpAcrossDistance: 0
minRegionArea: 2 minRegionArea: 2
manualCellSize: 0 manualCellSize: 0
cellSize: 0.16666667 cellSize: 0.16666667
manualTileSize: 0 manualTileSize: 0
tileSize: 256 tileSize: 256
accuratePlacement: 0 accuratePlacement: 0
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &705507993 --- !u!1 &705507993
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 705507995} - component: {fileID: 705507995}
- component: {fileID: 705507994} - component: {fileID: 705507994}
m_Layer: 0 m_Layer: 0
m_Name: Directional Light m_Name: Directional Light
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!108 &705507994 --- !u!108 &705507994
Light: Light:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 705507993} m_GameObject: {fileID: 705507993}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 8 serializedVersion: 8
m_Type: 1 m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1 m_Intensity: 1
m_Range: 10 m_Range: 10
m_SpotAngle: 30 m_SpotAngle: 30
m_CookieSize: 10 m_CookieSize: 10
m_Shadows: m_Shadows:
m_Type: 2 m_Type: 2
m_Resolution: -1 m_Resolution: -1
m_CustomResolution: -1 m_CustomResolution: -1
m_Strength: 1 m_Strength: 1
m_Bias: 0.05 m_Bias: 0.05
m_NormalBias: 0.4 m_NormalBias: 0.4
m_NearPlane: 0.2 m_NearPlane: 0.2
m_Cookie: {fileID: 0} m_Cookie: {fileID: 0}
m_DrawHalo: 0 m_DrawHalo: 0
m_Flare: {fileID: 0} m_Flare: {fileID: 0}
m_RenderMode: 0 m_RenderMode: 0
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
m_Lightmapping: 1 m_Lightmapping: 1
m_LightShadowCasterMode: 0 m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1} m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1 m_BounceIntensity: 1
m_ColorTemperature: 6570 m_ColorTemperature: 6570
m_UseColorTemperature: 0 m_UseColorTemperature: 0
m_ShadowRadius: 0 m_ShadowRadius: 0
m_ShadowAngle: 0 m_ShadowAngle: 0
--- !u!4 &705507995 --- !u!4 &705507995
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 705507993} m_GameObject: {fileID: 705507993}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &963194225 --- !u!1 &963194225
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 963194228} - component: {fileID: 963194228}
- component: {fileID: 963194227} - component: {fileID: 963194227}
- component: {fileID: 963194226} - component: {fileID: 963194226}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!81 &963194226 --- !u!81 &963194226
AudioListener: AudioListener:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_Enabled: 1 m_Enabled: 1
--- !u!20 &963194227 --- !u!20 &963194227
Camera: Camera:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_ClearFlags: 1 m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1 m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24} m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0} m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2 m_GateFitMode: 2
m_FocalLength: 50 m_FocalLength: 50
m_NormalizedViewPortRect: m_NormalizedViewPortRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
y: 0 y: 0
width: 1 width: 1
height: 1 height: 1
near clip plane: 0.3 near clip plane: 0.3
far clip plane: 1000 far clip plane: 1000
field of view: 60 field of view: 60
orthographic: 0 orthographic: 0
orthographic size: 5 orthographic size: 5
m_Depth: -1 m_Depth: -1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 0} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 1 m_HDR: 1
m_AllowMSAA: 1 m_AllowMSAA: 1
m_AllowDynamicResolution: 0 m_AllowDynamicResolution: 0
m_ForceIntoRT: 0 m_ForceIntoRT: 0
m_OcclusionCulling: 1 m_OcclusionCulling: 1
m_StereoConvergence: 10 m_StereoConvergence: 10
m_StereoSeparation: 0.022 m_StereoSeparation: 0.022
--- !u!4 &963194228 --- !u!4 &963194228
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10} m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -1,4 +1,4 @@
using System; using System;
public class BasicCounter public class BasicCounter
{ {

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
public class SampleComponent : MonoBehaviour public class SampleComponent : MonoBehaviour
{ {

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
public class TimerComponent : MonoBehaviour public class TimerComponent : MonoBehaviour
{ {

View File

@ -1,3 +1,3 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: b668d68a45bb48108ccda73269e3da7b guid: b668d68a45bb48108ccda73269e3da7b
timeCreated: 1610056748 timeCreated: 1610056748

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine.TestTools; using UnityEngine.TestTools;

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;

View File

@ -1,3 +1,3 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 818b22370d404398b87b47a922a435c9 guid: 818b22370d404398b87b47a922a435c9
timeCreated: 1610056889 timeCreated: 1610056889