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

Don't run doctests for generated functions #1966

Merged
merged 9 commits into from
Jun 13, 2023
Merged

Conversation

jonatanklosko
Copy link
Member

Functions defined with macros may have doctests, in particular use Mod may bring some, and we want to ignore these, since we can't point to them in the editor.

This includes two checks, one of which requires latest elixir, I will bump CI on the next RC.

@github-actions
Copy link

github-actions bot commented Jun 7, 2023

Uffizzi Preview deployment-27810 was deleted.

@petrus-jvrensburg
Copy link

When trying this branch, it's no longer tripping on the doctests, but I'm running into a new Enum.OutOfBoundsError.

To reproduce:

Mix.install([
  :ex_cldr,
  :jason
])

defmodule DemoApp.Backend do
  use Cldr,
    locales: ["en"],
    default_locale: "en",
    providers: [],
    json_library: Jason
end

When evaluating this, the error I'm seeing is:

07:35:36.379 [error] GenServer #PID<55119.142.0> terminating
** (Enum.OutOfBoundsError) out of bounds error
    (elixir 1.14.5) lib/enum.ex:1072: Enum.fetch!/2
    (livebook 0.9.2) lib/livebook/runtime/evaluator/doctests.ex:70: Livebook.Runtime.Evaluator.Doctests.doctest_at_line?/2
    (elixir 1.14.5) lib/enum.ex:4197: Enum.filter_list/2
    (livebook 0.9.2) lib/livebook/runtime/evaluator/doctests.ex:47: Livebook.Runtime.Evaluator.Doctests.do_run/2
    (livebook 0.9.2) lib/livebook/runtime/evaluator.ex:463: Livebook.Runtime.Evaluator.continue_do_evaluate_code/6
    (livebook 0.9.2) lib/livebook/runtime/evaluator.ex:330: Livebook.Runtime.Evaluator.loop/1
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:DOWN, #Reference<55119.932864469.3854827526.61511>, :process, #PID<55119.141.0>, {%Enum.OutOfBoundsError{message: "out of bounds error"}, [{Enum, :fetch!, 2, [file: 'lib/enum.ex', line: 1072, error_info: %{module: Exception}]}, {Livebook.Runtime.Evaluator.Doctests, :doctest_at_line?, 2, [file: 'lib/livebook/runtime/evaluator/doctests.ex', line: 70]}, {Enum, :filter_list, 2, [file: 'lib/enum.ex', line: 4197]}, {Livebook.Runtime.Evaluator.Doctests, :do_run, 2, [file: 'lib/livebook/runtime/evaluator/doctests.ex', line: 47]}, {Livebook.Runtime.Evaluator, :continue_do_evaluate_code, 6, [file: 'lib/livebook/runtime/evaluator.ex', line: 463]}, {Livebook.Runtime.Evaluator, :loop, 1, [file: 'lib/livebook/runtime/evaluator.ex', line: 330]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}

07:35:36.379 [error] GenServer #PID<0.142.0> terminating
** (Enum.OutOfBoundsError) out of bounds error
    (elixir 1.14.5) lib/enum.ex:1072: Enum.fetch!/2
    lib/livebook/runtime/evaluator/doctests.ex:70: Livebook.Runtime.Evaluator.Doctests.doctest_at_line?/2
    (elixir 1.14.5) lib/enum.ex:4197: Enum.filter_list/2
    lib/livebook/runtime/evaluator/doctests.ex:47: Livebook.Runtime.Evaluator.Doctests.do_run/2
    lib/livebook/runtime/evaluator.ex:463: Livebook.Runtime.Evaluator.continue_do_evaluate_code/6
    lib/livebook/runtime/evaluator.ex:330: Livebook.Runtime.Evaluator.loop/1
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:DOWN, #Reference<0.932864469.3854827526.61511>, :process, #PID<0.141.0>, {%Enum.OutOfBoundsError{message: "out of bounds error"}, [{Enum, :fetch!, 2, [file: 'lib/enum.ex', line: 1072, error_info: %{module: Exception}]}, {Livebook.Runtime.Evaluator.Doctests, :doctest_at_line?, 2, [file: 'lib/livebook/runtime/evaluator/doctests.ex', line: 70]}, {Enum, :filter_list, 2, [file: 'lib/enum.ex', line: 4197]}, {Livebook.Runtime.Evaluator.Doctests, :do_run, 2, [file: 'lib/livebook/runtime/evaluator/doctests.ex', line: 47]}, {Livebook.Runtime.Evaluator, :continue_do_evaluate_code, 6, [file: 'lib/livebook/runtime/evaluator.ex', line: 463]}, {Livebook.Runtime.Evaluator, :loop, 1, [file: 'lib/livebook/runtime/evaluator.ex', line: 330]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}
State: %{buffer: [], ebin_path: "/var/folders/bx/rsc2pf2d61bf5fzzjj7jyph00000gn/T/livebook_runtime/pyycbwp24i3cfqqge7p4edmcyfpnueec/ebin", encoding: :unicode, evaluator: #PID<0.141.0>, evaluator_monitor: #Reference<0.932864469.3854827526.61511>, file: "/Users/petrus/Desktop/cldr_examples.livemd#cell:jlbqt3a7kxugj5m3hjtz4sbcj3uh7lfa", input_cache: %{}, modules_defined: MapSet.new([DemoApp.Backend, DemoApp.Backend.AcceptLanguage, DemoApp.Backend.Locale, DemoApp.Backend.Number.Cardinal, DemoApp.Backend.Number.Ordinal, DemoApp.Backend.Number.PluralRule.Range]), object_tracker: #PID<0.138.0>, ref: "jlbqt3a7kxugj5m3hjtz4sbcj3uh7lfa", runtime_broadcast_to: #PID<11810.5328.0>, send_to: #PID<11810.5327.0>, token_count: 0, tracer_info: %Livebook.Runtime.Evaluator.Tracer{modules_used: MapSet.new([Access, Range, Cldr.AcceptLanguage, Cldr, Decimal, :maps, :erlang, Enum, Float, List, :elixir_quote, Module, Kernel.Utils, Kernel.Typespec, Cldr.Map, Cldr.Config, Cldr.Number.PluralRule, Cldr.Number.PluralRule.Compiler, String.Chars, Path, Map, Keyword, Kernel, Kernel.LexicalTracker, Cldr.Backend.Compiler, Cldr.Math, File, Cldr.Locale.Loader, :elixir_utils, Regex, Cldr.LanguageTag, String, :elixir_bootstrap, :elixir_module, Cldr.Substitution, ...]), modules_defined: %{DemoApp.Backend => [opts: {DemoApp.Backend, 2}, result: Kernel], DemoApp.Backend.AcceptLanguage => [backend: Cldr.Backend, config: Cldr.AcceptLanguage.Backend, config: Cldr.Backend, config: Cldr.Locale.Backend, funs: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 189}, funs: {DemoApp.Backend, 192}, funs: {DemoApp.Backend, 195}, funs: {DemoApp.Backend, 198}, funs: {DemoApp.Backend, 201}, funs: {DemoApp.Backend, 204}, funs: {DemoApp.Backend, 207}, funs: {DemoApp.Backend, 210}, known_locale_names: Cldr.Locale.Backend, opts: {DemoApp.Backend, 186}, opts: {DemoApp.Backend, 189}, opts: {DemoApp.Backend, 192}, opts: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 198}, opts: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 204}, opts: {DemoApp.Backend, 207}, opts: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 186}, target: {DemoApp.Backend, 189}, target: {DemoApp.Backend, 192}, target: {DemoApp.Backend, 195}, target: {DemoApp.Backend, 198}, target: {DemoApp.Backend, 201}, target: {DemoApp.Backend, 204}, target: {DemoApp.Backend, ...}, target: {...}], DemoApp.Backend.Locale => [backend: Cldr.Backend, config: Cldr.Backend, config: Cldr.Locale.Backend, funs: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 189}, funs: {DemoApp.Backend, 192}, funs: {DemoApp.Backend, 195}, funs: {DemoApp.Backend, 198}, funs: {DemoApp.Backend, 201}, funs: {DemoApp.Backend, 204}, funs: {DemoApp.Backend, 207}, funs: {DemoApp.Backend, 210}, known_locale_names: Cldr.Locale.Backend, opts: {DemoApp.Backend, 186}, opts: {DemoApp.Backend, 189}, opts: {DemoApp.Backend, 192}, opts: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 198}, opts: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 204}, opts: {DemoApp.Backend, 207}, opts: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 186}, target: {DemoApp.Backend, 189}, target: {DemoApp.Backend, 192}, target: {DemoApp.Backend, 195}, target: {DemoApp.Backend, 198}, target: {DemoApp.Backend, 201}, target: {DemoApp.Backend, 204}, target: {DemoApp.Backend, ...}, target: {...}], DemoApp.Backend.Number.Cardinal => [backend: Cldr.Backend, config: Cldr.AcceptLanguage.Backend, config: Cldr.Backend, config: Cldr.Locale.Backend, funs: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 189}, funs: {DemoApp.Backend, 192}, funs: {DemoApp.Backend, 195}, funs: {DemoApp.Backend, 198}, funs: {DemoApp.Backend, 201}, funs: {DemoApp.Backend, 204}, funs: {DemoApp.Backend, 207}, funs: {DemoApp.Backend, 210}, known_locale_names: Cldr.Locale.Backend, opts: {DemoApp.Backend, 186}, opts: {DemoApp.Backend, 189}, opts: {DemoApp.Backend, 192}, opts: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 198}, opts: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 204}, opts: {DemoApp.Backend, 207}, opts: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 186}, target: {DemoApp.Backend, 189}, target: {DemoApp.Backend, 192}, target: {DemoApp.Backend, 195}, target: {DemoApp.Backend, 198}, target: {DemoApp.Backend, ...}, target: {...}, ...], DemoApp.Backend.Number.Ordinal => [backend: Cldr.Backend, config: Cldr.AcceptLanguage.Backend, config: Cldr.Backend, config: Cldr.Locale.Backend, funs: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 189}, funs: {DemoApp.Backend, 192}, funs: {DemoApp.Backend, 195}, funs: {DemoApp.Backend, 198}, funs: {DemoApp.Backend, 201}, funs: {DemoApp.Backend, 204}, funs: {DemoApp.Backend, 207}, funs: {DemoApp.Backend, 210}, known_locale_names: Cldr.Locale.Backend, opts: {DemoApp.Backend, 186}, opts: {DemoApp.Backend, 189}, opts: {DemoApp.Backend, 192}, opts: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 198}, opts: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 204}, opts: {DemoApp.Backend, 207}, opts: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 186}, target: {DemoApp.Backend, 189}, target: {DemoApp.Backend, 192}, target: {DemoApp.Backend, 195}, target: {DemoApp.Backend, ...}, target: {...}, ...], DemoApp.Backend.Number.PluralRule.Range => [funs: {DemoApp.Backend, 204}, funs: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 195}, opts: {DemoApp.Backend, 198}, target: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 186}, funs: {DemoApp.Backend, 189}, target: {DemoApp.Backend, 189}, opts: {DemoApp.Backend, 189}, config: Cldr.AcceptLanguage.Backend, target: {DemoApp.Backend, 201}, opts: {DemoApp.Backend, 201}, known_locale_names: Cldr.Locale.Backend, target: {DemoApp.Backend, 210}, target: {DemoApp.Backend, 207}, opts: {DemoApp.Backend, 186}, backend: Cldr.Backend, opts: {DemoApp.Backend, 204}, target: {DemoApp.Backend, 192}, config: Cldr.Backend, target: {DemoApp.Backend, 198}, funs: {DemoApp.Backend, 207}, target: {DemoApp.Backend, 204}, opts: {DemoApp.Backend, 192}, config: Cldr.Number.PluralRule, opts: {...}, ...]}, aliases_used: MapSet.new([Range, Cldr.AcceptLanguage, Cldr, DemoApp.Backend.Number.Ordinal, Decimal, LanguageTag, Enum, Float, List, PluralRule, Locale, Module, DemoApp.Backend.AcceptLanguage, ArgumentError, Kernel.Utils, Jason, Config, Kernel.Typespec, Cldr.Map, Cldr.Config, Math, Cldr.Number.PluralRule, DemoApp.Backend.Number, Cldr.Number.PluralRule.Compiler, Path, Map, Keyword, Kernel, Kernel.LexicalTracker, DemoApp.Backend.Number.Cardinal, Cldr.Backend.Compiler, Cldr.Math, File, ...]), aliases_defined: %{}, requires_used: MapSet.new([Cldr, Cldr.Backend.Compiler, Cldr.Number.PluralRule, Kernel, :elix (truncated)

@jonatanklosko
Copy link
Member Author

@petrus-jvrensburg thanks for checking, should be good now!

@petrus-jvrensburg
Copy link

Yes, that fixes it. Thanks a lot!

[_ | _] = path -> List.starts_with?(path, :code.lib_dir())
_ -> false
end
app == :erts or
Copy link
Member Author

@jonatanklosko jonatanklosko Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim in iex

Application.get_application(:atomics)
#=> nil

in iex -S mix

Application.get_application(:atomics)
# => :erts

Given the test fails, I think this changed in elixir-lang/elixir#12642, but probably expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks! I commented out the failing test and left a TODO, so we can marge the fix :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I will leave the check and have the TODO to remove it, this way we keep the test.

@jonatanklosko jonatanklosko merged commit d5f9aaf into main Jun 13, 2023
@jonatanklosko jonatanklosko deleted the jk-generated-doctests branch June 13, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants