BadScript 2
Loading...
Searching...
No Matches
BadUnitTestContext.cs
Go to the documentation of this file.
6
7using NUnit.Framework;
8
10
15{
19 private readonly List<BadNUnitTestCase> m_Cases;
20
24 private readonly BadRuntime m_Runtime;
25
29 private readonly List<BadFunction> m_Setup;
30
34 private readonly List<BadFunction> m_Teardown;
35
39 private readonly string m_WorkingDir;
40
50 string workingDir,
51 List<BadNUnitTestCase> cases,
52 List<BadFunction> setup,
53 List<BadFunction> teardown,
54 BadRuntime runtime)
55 {
56 m_Cases = cases;
57 m_Setup = setup;
58 m_Teardown = teardown;
59 m_Runtime = runtime;
60 m_WorkingDir = workingDir;
61 }
62
67 private static void Run(IEnumerable<BadObject> enumerable)
68 {
69 foreach (BadObject _ in enumerable)
70 {
71 //Execute
72 }
73 }
74
78 public void Setup()
79 {
80 Run(RunSetup());
81 }
82
86 public void Teardown()
87 {
89 }
90
95 public void Run(BadNUnitTestCase test)
96 {
97 Run(RunTestCase(test));
98 }
99
105 {
106 return m_Cases.ToArray();
107 }
108
114 public IEnumerable<BadObject> RunSetup()
115 {
116 for (int i = m_Setup.Count - 1; i >= 0; i--)
117 {
118 BadFunction function = m_Setup[i];
120
121 foreach (BadObject o in function.Invoke(Array.Empty<BadObject>(), caller))
122 {
123 yield return o;
124 }
125 }
126 }
127
133 public IEnumerable<BadObject> RunTeardown()
134 {
135 for (int i = m_Teardown.Count - 1; i >= 0; i--)
136 {
137 BadFunction function = m_Teardown[i];
139
140 foreach (BadObject o in function.Invoke(Array.Empty<BadObject>(), caller))
141 {
142 yield return o;
143 }
144 }
145 }
146
153 private IEnumerable<BadObject> RunTestCase(BadNUnitTestCase testCase)
154 {
155 TestContext.WriteLine($"Running test '{testCase.TestName}'");
157
159 new BadTask(
160 new BadInteropRunnable(testCase.Function!.Invoke(Array.Empty<BadObject>(), caller).GetEnumerator()),
161 testCase.TestName
162 ),
163 true
164 );
165
167 {
169
170 yield return BadObject.Null;
171 }
172 }
173}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
BadExecutionContext CreateContext(string workingDirectory)
Creates a new Context with the configured Options.
Implements a Runnable that can return a value.
Implements a Task Object.
Definition BadTask.cs:17
void RunStep()
Runs a single step of the Task Runner.
void AddTask(BadTask task, bool runImmediately=false)
Adds a Task to the Task Runner.
static readonly BadTaskRunner Instance
The Task Runner Instance.
bool IsIdle
Is true if there are no tasks to run.
Represents a BadScript NUnit Test Case.
BadFunction? Function
The Function to Test.
Implements a BadScript NUnit Test Context.
readonly List< BadNUnitTestCase > m_Cases
The Test Cases.
void Run(BadNUnitTestCase test)
Runs a Test Case.
BadUnitTestContext(string workingDir, List< BadNUnitTestCase > cases, List< BadFunction > setup, List< BadFunction > teardown, BadRuntime runtime)
Constructs a new BadUnitTestContext.
IEnumerable< BadObject > RunTeardown()
Runs all Teardown Functions.
static void Run(IEnumerable< BadObject > enumerable)
Runs an enumeration.
readonly string m_WorkingDir
The Working Directory.
readonly List< BadFunction > m_Teardown
The Teardown Functions.
BadNUnitTestCase[] GetTestCases()
Returns all Test Cases.
IEnumerable< BadObject > RunTestCase(BadNUnitTestCase testCase)
Runs a Testcase.
void Teardown()
Runs all Teardown Functions.
readonly List< BadFunction > m_Setup
The Setup Functions.
IEnumerable< BadObject > RunSetup()
Runs all Setup Functions.
readonly BadRuntime m_Runtime
The Runtime.
The Execution Context. Every execution of a script needs a context the script is running in....
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a function that can be called from the script.
IEnumerable< BadObject > Invoke(BadObject[] args, BadExecutionContext caller)
Invokes the function with the specified arguments.
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains NUnit Extensions and APIs for the BadScript2 Runtime.
Definition BadNUnitApi.cs:7
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.