/
case.ex
823 lines (620 loc) · 24.1 KB
/
case.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
defmodule ExUnit.DuplicateTestError do
defexception [:message]
end
defmodule ExUnit.DuplicateDescribeError do
defexception [:message]
end
defmodule ExUnit.Case do
@moduledoc """
Helpers for defining test cases.
This module must be used in other modules as a way to configure
and prepare them for testing.
When used, it accepts the following options:
* `:async` - configures tests in this module to run concurrently with
tests in other modules. Tests in the same module never run concurrently.
It should be enabled only if tests do not change any global state.
Defaults to `false`.
* `:register` - when `false`, does not register this module within
ExUnit server. This means the module won't run when ExUnit suite runs.
> #### `use ExUnit.Case` {: .info}
>
> When you `use ExUnit.Case`, it will import the functionality
> from `ExUnit.Assertions`, `ExUnit.Callbacks`, `ExUnit.DocTest`,
> and this module itself.
## Examples
defmodule AssertionTest do
# Use the module
use ExUnit.Case, async: true
# The "test" macro is imported by ExUnit.Case
test "always pass" do
assert true
end
end
## Context
All tests receive a context as an argument. The context is particularly
useful for sharing information between callbacks and tests:
defmodule KVTest do
use ExUnit.Case
setup do
{:ok, pid} = KV.start_link()
{:ok, pid: pid}
end
test "stores key-value pairs", context do
assert KV.put(context[:pid], :hello, :world) == :ok
assert KV.get(context[:pid], :hello) == :world
end
end
As the context is a map, it can be pattern matched on to extract
information:
test "stores key-value pairs", %{pid: pid} = _context do
assert KV.put(pid, :hello, :world) == :ok
assert KV.get(pid, :hello) == :world
end
## Tags
The context is used to pass information from the callbacks to
the test. In order to pass information from the test to the
callback, ExUnit provides tags.
By tagging a test, the tag value can be accessed in the context,
allowing the developer to customize the test. Let's see an
example:
defmodule FileTest do
# Changing directory cannot be async
use ExUnit.Case, async: false
setup context do
# Read the :cd tag value
if cd = context[:cd] do
prev_cd = File.cwd!()
File.cd!(cd)
on_exit(fn -> File.cd!(prev_cd) end)
end
:ok
end
@tag cd: "fixtures"
test "reads UTF-8 fixtures" do
File.read("README.md")
end
end
In the example above, we have defined a tag called `:cd` that is
read in the setup callback to configure the working directory the
test is going to run on.
Tags are also very effective when used with case templates
(`ExUnit.CaseTemplate`) allowing callbacks in the case template
to customize the test behaviour.
Note a tag can be set in two different ways:
@tag key: value
@tag :key # equivalent to setting @tag key: true
If a tag is given more than once, the last value wins.
### Module and describe tags
A tag can be set for all tests in a module or describe block by
setting `@moduletag` or `@describetag` inside each context
respectively:
defmodule ApiTest do
use ExUnit.Case
@moduletag :external
describe "makes calls to the right endpoint" do
@describetag :endpoint
# ...
end
end
If you are setting a `@moduletag` or `@describetag` attribute, you must
set them after your call to `use ExUnit.Case` otherwise you will see
compilation errors.
If the same key is set via `@tag`, the `@tag` value has higher
precedence.
The `setup_all` blocks only receive tags that are set using `@moduletag`.
### Known tags
The following tags are set automatically by ExUnit and are
therefore reserved:
* `:module` - the module on which the test was defined
* `:file` - the file on which the test was defined
* `:line` - the line on which the test was defined
* `:test` - the test name
* `:async` - if the test case is in async mode
* `:registered` - used for `ExUnit.Case.register_attribute/3` values
* `:describe` - the describe block the test belongs to
* `:describe_line` - the line the describe block begins on
* `:doctest` - the module or the file being doctested (if a doctest)
* `:doctest_line` - the line the doctest was defined (if a doctest)
* `:doctest_data` - additional metadata about doctests (if a doctest)
* `:test_type` - the test type used when printing test results.
It is set by ExUnit to `:test`, `:doctest` and so on, but is customizable.
The following tags customize how tests behave:
* `:capture_log` - see the "Log Capture" section below
* `:skip` - skips the test with the given reason
* `:timeout` - customizes the test timeout in milliseconds (defaults to 60000).
Accepts `:infinity` as a timeout value.
* `:tmp_dir` - (since v1.11.0) see the "Tmp Dir" section below
## Filters
Tags can also be used to identify specific tests, which can then
be included or excluded using filters. The most common functionality
is to exclude some particular tests from running, which can be done
via `ExUnit.configure/1`:
# Exclude all external tests from running
ExUnit.configure(exclude: [external: true])
From now on, ExUnit will not run any test that has the `:external` option
set to `true`. This behaviour can be reversed with the `:include` option
which is usually passed through the command line:
$ mix test --include external:true
Run `mix help test` for more information on how to run filters via Mix.
Another use case for tags and filters is to exclude all tests that have
a particular tag by default, regardless of its value, and include only
a certain subset:
ExUnit.configure(exclude: :os, include: [os: :unix])
A given include/exclude filter can be given more than once:
ExUnit.configure(exclude: [os: :unix, os: :windows])
Keep in mind that all tests are included by default, so unless they are
excluded first, the `include` option has no effect.
## Log Capture
ExUnit can optionally suppress printing of log messages that are generated
during a test. Log messages generated while running a test are captured and
only if the test fails are they printed to aid with debugging.
You can opt into this behaviour for individual tests by tagging them with
`:capture_log` or enable log capture for all tests in the ExUnit configuration:
ExUnit.start(capture_log: true)
This default can be overridden by `@tag capture_log: false` or
`@moduletag capture_log: false`.
Since `setup_all` blocks don't belong to a specific test, log messages generated
in them (or between tests) are never captured. If you want to suppress these
messages as well, remove the console backend globally by setting:
config :logger, backends: []
## Tmp Dir
ExUnit automatically creates a temporary directory for tests tagged with
`:tmp_dir` and puts the path to that directory into the test context.
The directory is removed before being created to ensure we start with a blank
slate.
The temporary directory path is unique (includes the test module and test name)
and thus appropriate for running tests concurrently. You can customize the path
further by setting the tag to a string, e.g.: `tmp_dir: "my_path"`, which would
make the final path to be: `tmp/<module>/<test>/my_path`.
Example:
defmodule MyTest do
use ExUnit.Case, async: true
@tag :tmp_dir
test "with tmp_dir", %{tmp_dir: tmp_dir} do
assert tmp_dir =~ "with tmp_dir"
assert File.dir?(tmp_dir)
end
end
As with other tags, `:tmp_dir` can also be set as `@moduletag` and
`@describetag`.
"""
@type env :: module() | Macro.Env.t()
@reserved [:module, :file, :line, :test, :async, :registered, :describe]
@doc false
defmacro __using__(opts) do
quote do
unless ExUnit.Case.__register__(__MODULE__, unquote(opts)) do
use ExUnit.Callbacks
end
import ExUnit.Callbacks
import ExUnit.Assertions
import ExUnit.Case, only: [describe: 2, test: 1, test: 2, test: 3]
import ExUnit.DocTest
end
end
@doc false
def __register__(module, opts) do
unless Keyword.keyword?(opts) do
raise ArgumentError,
~s(the argument passed to "use ExUnit.Case" must be a list of options, ) <>
~s(got: #{inspect(opts)})
end
registered? = Module.has_attribute?(module, :ex_unit_tests)
unless registered? do
tag_check = Enum.any?([:moduletag, :describetag, :tag], &Module.has_attribute?(module, &1))
if tag_check do
raise "you must set @tag, @describetag, and @moduletag after the call to \"use ExUnit.Case\""
end
accumulate_attributes = [
:ex_unit_tests,
:tag,
:describetag,
:moduletag,
:ex_unit_registered_test_attributes,
:ex_unit_registered_describe_attributes,
:ex_unit_registered_module_attributes
]
Enum.each(accumulate_attributes, &Module.register_attribute(module, &1, accumulate: true))
persisted_attributes = [:ex_unit_async]
Enum.each(persisted_attributes, &Module.register_attribute(module, &1, persist: true))
if Keyword.get(opts, :register, true) do
Module.put_attribute(module, :after_compile, ExUnit.Case)
end
Module.put_attribute(module, :before_compile, ExUnit.Case)
end
async? = opts[:async]
if is_boolean(async?) or not registered? do
Module.put_attribute(module, :ex_unit_async, async? || false)
end
registered?
end
@doc """
Defines a test with `message`.
The test may also define a pattern, which will be matched
against the test context. For more information on contexts, see
`ExUnit.Callbacks`.
## Examples
test "true is equal to true" do
assert true == true
end
"""
defmacro test(message, var \\ quote(do: _), contents) do
unless is_tuple(var) do
IO.warn(
"test context is always a map. The pattern " <>
"#{inspect(Macro.to_string(var))} will never match",
Macro.Env.stacktrace(__CALLER__)
)
end
contents =
case contents do
[do: block] ->
quote do
unquote(block)
:ok
end
_ ->
quote do
try(unquote(contents))
:ok
end
end
var = Macro.escape(var)
contents = Macro.escape(contents, unquote: true)
%{module: mod, file: file, line: line} = __CALLER__
quote bind_quoted: [
var: var,
contents: contents,
message: message,
mod: mod,
file: file,
line: line
] do
name = ExUnit.Case.register_test(mod, file, line, :test, message, [])
def unquote(name)(unquote(var)), do: unquote(contents)
end
end
@doc """
Defines a not implemented test with a string.
Provides a convenient macro that allows a test to be defined
with a string, but not yet implemented. The resulting test will
always fail and print a "Not implemented" error message. The
resulting test case is also tagged with `:not_implemented`.
## Examples
test "this will be a test in future"
"""
defmacro test(message) do
%{module: mod, file: file, line: line} = __CALLER__
quote bind_quoted: binding() do
name = ExUnit.Case.register_test(mod, file, line, :test, message, [:not_implemented])
def unquote(name)(_), do: flunk("Not implemented")
end
end
@doc """
Describes tests together.
Every describe block receives a name which is used as prefix for
upcoming tests. Inside a block, `ExUnit.Callbacks.setup/1` may be
invoked and it will define a setup callback to run only for the
current block. The describe name is also added as a tag, allowing
developers to run tests for specific blocks.
## Examples
defmodule StringTest do
use ExUnit.Case, async: true
describe "String.capitalize/1" do
test "first grapheme is in uppercase" do
assert String.capitalize("hello") == "Hello"
end
test "converts remaining graphemes to lowercase" do
assert String.capitalize("HELLO") == "Hello"
end
end
end
When using Mix, you can run all tests in a describe block by name:
$ mix test --only describe:"String.capitalize/1"
or by passing the exact line the describe block starts on:
$ mix test path/to/file:123
Note describe blocks cannot be nested. Instead of relying on hierarchy
for composition, developers should build on top of named setups. For
example:
defmodule UserManagementTest do
use ExUnit.Case, async: true
describe "when user is logged in and is an admin" do
setup [:log_user_in, :set_type_to_admin]
test ...
end
describe "when user is logged in and is a manager" do
setup [:log_user_in, :set_type_to_manager]
test ...
end
defp log_user_in(context) do
# ...
end
end
By forbidding hierarchies in favor of named setups, it is straightforward
for the developer to glance at each describe block and know exactly the
setup steps involved.
"""
@doc since: "1.3.0"
defmacro describe(message, do: block) do
definition =
quote unquote: false do
defp unquote(name)(var!(context)), do: unquote(body)
end
quote do
ExUnit.Callbacks.__describe__(__MODULE__, __ENV__.line, unquote(message), fn
message, describes ->
res = unquote(block)
case ExUnit.Callbacks.__describe__(__MODULE__, message, describes) do
{nil, nil} -> :ok
{name, body} -> unquote(definition)
end
res
end)
end
end
@doc false
defmacro __before_compile__(env) do
tests =
env.module
|> Module.get_attribute(:ex_unit_tests)
|> Enum.reverse()
|> Macro.escape()
moduletag = Module.get_attribute(env.module, :moduletag)
tags =
moduletag
|> normalize_tags()
|> validate_tags()
|> Map.new()
|> Map.merge(%{module: env.module, case: env.module})
quote do
def __ex_unit__ do
%ExUnit.TestModule{
file: __ENV__.file,
name: __MODULE__,
tags: unquote(Macro.escape(tags)),
tests: unquote(tests)
}
end
end
end
@doc false
def __after_compile__(%{module: module}, _) do
cond do
Process.whereis(ExUnit.Server) == nil ->
unless Code.can_await_module_compilation?() do
raise "cannot use ExUnit.Case without starting the ExUnit application, " <>
"please call ExUnit.start() or explicitly start the :ex_unit app"
end
Module.get_attribute(module, :ex_unit_async) ->
ExUnit.Server.add_async_module(module)
true ->
ExUnit.Server.add_sync_module(module)
end
end
@doc """
Registers a function to run as part of this case.
This is used by third-party projects, like QuickCheck, to
implement macros like `property/3` that works like `test`
but instead defines a property. See `test/3` implementation
for an example of invoking this function.
The test type will be converted to a string and pluralized for
display. You can use `ExUnit.plural_rule/2` to set a custom
pluralization.
"""
@doc since: "1.10.0"
def register_test(mod, file, line, test_type, name, tags) do
unless Module.has_attribute?(mod, :ex_unit_tests) do
raise "cannot define #{test_type}. Please make sure you have invoked " <>
"\"use ExUnit.Case\" in the current module"
end
registered_attribute_keys = [
:ex_unit_registered_module_attributes,
:ex_unit_registered_describe_attributes,
:ex_unit_registered_test_attributes
]
registered =
for key <- registered_attribute_keys,
attribute <- Module.get_attribute(mod, key),
into: %{} do
{attribute, Module.get_attribute(mod, attribute)}
end
moduletag = Module.get_attribute(mod, :moduletag)
tag = Module.delete_attribute(mod, :tag)
async = Module.get_attribute(mod, :ex_unit_async)
{name, describe, describe_line, describetag} =
case Module.get_attribute(mod, :ex_unit_describe) do
{line, describe, _counter} ->
test_name = validate_test_name("#{test_type} #{describe} #{name}")
{test_name, describe, line, Module.get_attribute(mod, :describetag)}
nil ->
test_name = validate_test_name("#{test_type} #{name}")
{test_name, nil, nil, []}
end
if Module.defines?(mod, {name, 1}) do
raise ExUnit.DuplicateTestError, ~s("#{name}" is already defined in #{inspect(mod)})
end
tags =
(tags ++ tag ++ describetag ++ moduletag)
|> normalize_tags()
|> validate_tags()
|> Map.merge(%{
line: line,
file: file,
registered: registered,
async: async,
describe: describe,
describe_line: describe_line,
test_type: test_type
})
test = %ExUnit.Test{name: name, case: mod, tags: tags, module: mod}
Module.put_attribute(mod, :ex_unit_tests, test)
for attribute <- Module.get_attribute(mod, :ex_unit_registered_test_attributes) do
Module.delete_attribute(mod, attribute)
end
name
end
@doc """
Registers a test with the given environment.
This function is deprecated in favor of `register_test/6` which performs
better under tight loops by avoiding `__ENV__`.
"""
# TODO: Deprecate on Elixir v1.17
@doc deprecated: "Use register_test/6 instead"
@doc since: "1.3.0"
def register_test(%{module: mod, file: file, line: line}, test_type, name, tags) do
register_test(mod, file, line, test_type, name, tags)
end
@doc """
Registers a new attribute to be used during `ExUnit.Case` tests.
The attribute values will be available through `context.registered`.
Registered values are cleared after each `test/3` similar
to `@tag`.
This function takes the same options as `Module.register_attribute/3`.
## Examples
defmodule MyTest do
use ExUnit.Case
ExUnit.Case.register_attribute(__MODULE__, :fixtures, accumulate: true)
@fixtures :user
@fixtures {:post, insert: false}
test "using custom attribute", context do
assert context.registered.fixtures == [{:post, insert: false}, :user]
end
test "custom attributes are cleared per test", context do
assert context.registered.fixtures == []
end
end
"""
@doc since: "1.3.0"
@spec register_attribute(env, atom, keyword) :: :ok
def register_attribute(env, name, opts \\ [])
def register_attribute(%{module: mod}, name, opts), do: register_attribute(mod, name, opts)
def register_attribute(mod, name, opts) when is_atom(mod) and is_atom(name) and is_list(opts) do
register_attribute(:ex_unit_registered_test_attributes, mod, name, opts)
end
@doc """
Registers a new describe attribute to be used during `ExUnit.Case` tests.
The attribute values will be available through `context.registered`.
Registered values are cleared after each `describe/2` similar
to `@describetag`.
This function takes the same options as `Module.register_attribute/3`.
## Examples
defmodule MyTest do
use ExUnit.Case
ExUnit.Case.register_describe_attribute(__MODULE__, :describe_fixtures, accumulate: true)
describe "using custom attribute" do
@describe_fixtures :user
@describe_fixtures {:post, insert: false}
test "has attribute", context do
assert context.registered.describe_fixtures == [{:post, insert: false}, :user]
end
end
describe "custom attributes are cleared per describe" do
test "doesn't have attributes", context do
assert context.registered.describe_fixtures == []
end
end
end
"""
@doc since: "1.10.0"
@spec register_describe_attribute(env, atom, keyword) :: :ok
def register_describe_attribute(env, name, opts \\ [])
def register_describe_attribute(%{module: mod}, name, opts) do
register_describe_attribute(mod, name, opts)
end
def register_describe_attribute(mod, name, opts)
when is_atom(mod) and is_atom(name) and is_list(opts) do
register_attribute(:ex_unit_registered_describe_attributes, mod, name, opts)
end
@doc """
Registers a new module attribute to be used during `ExUnit.Case` tests.
The attribute values will be available through `context.registered`.
This function takes the same options as `Module.register_attribute/3`.
## Examples
defmodule MyTest do
use ExUnit.Case
ExUnit.Case.register_module_attribute(__MODULE__, :module_fixtures, accumulate: true)
@module_fixtures :user
@module_fixtures {:post, insert: false}
test "using custom attribute", context do
assert context.registered.module_fixtures == [{:post, insert: false}, :user]
end
test "still using custom attribute", context do
assert context.registered.module_fixtures == [{:post, insert: false}, :user]
end
end
"""
@doc since: "1.10.0"
@spec register_module_attribute(env, atom, keyword) :: :ok
def register_module_attribute(env, name, opts \\ [])
def register_module_attribute(%{module: mod}, name, opts) do
register_module_attribute(mod, name, opts)
end
def register_module_attribute(mod, name, opts)
when is_atom(mod) and is_atom(name) and is_list(opts) do
register_attribute(:ex_unit_registered_module_attributes, mod, name, opts)
end
defp register_attribute(type, mod, name, opts) do
validate_registered_attribute!(type, mod, name)
Module.register_attribute(mod, name, opts)
Module.put_attribute(mod, type, name)
end
defp validate_registered_attribute!(type, mod, name) do
registered_attribute_keys = [
:ex_unit_registered_module_attributes,
:ex_unit_registered_describe_attributes,
:ex_unit_registered_test_attributes
]
for key <- registered_attribute_keys,
type != key and name in Module.get_attribute(mod, key) do
raise ArgumentError, "cannot register attribute #{inspect(name)} multiple times"
end
if Module.has_attribute?(mod, name) do
raise "you must set @#{name} after it has been registered"
end
end
@doc """
Returns the most recently registered test case as an `%ExUnit.Test{}`
struct.
This is used by third-party utilities to allow compile-time configuration
using test tags without having to explicitly pass the test context at
run-time. It is intended to be invoked in macros before the test module
is compiled.
Raises if called with a module that has already been compiled.
"""
@doc since: "1.15.0"
@spec get_last_registered_test(env) :: ExUnit.Test.t() | nil
def get_last_registered_test(%{module: mod}) do
get_last_registered_test(mod)
end
def get_last_registered_test(mod) when is_atom(mod) do
Module.get_last_attribute(mod, :ex_unit_tests)
end
defp validate_tags(tags) do
for tag <- @reserved, Map.has_key?(tags, tag) do
raise "cannot set tag #{inspect(tag)} because it is reserved by ExUnit"
end
unless is_atom(tags[:test_type]) do
raise("value for tag \":test_type\" must be an atom")
end
tags
end
defp validate_test_name(name) do
try do
String.to_atom(name)
rescue
SystemLimitError ->
raise SystemLimitError, """
the computed name of a test (which includes its type, the name of its parent describe \
block if present, and the test name itself) must be shorter than 255 characters, \
got: #{inspect(name)}
"""
end
end
defp normalize_tags(tags) do
Enum.reduce(Enum.reverse(tags), %{}, fn
{key, value}, acc -> Map.put(acc, key, value)
tag, acc when is_atom(tag) -> Map.put(acc, tag, true)
tag, acc when is_list(tag) -> Enum.into(tag, acc)
end)
end
end