-
Notifications
You must be signed in to change notification settings - Fork 0
CodeRabbit Generated Unit Tests: Add unit tests for PR changes #7
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
Open
coderabbitai
wants to merge
1
commit into
main
Choose a base branch
from
coderabbitai/utg/af8eab1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,313
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,250 @@ | ||
| %% | ||
| %% Copyright (c) 2026 Winford (UncleGrumpy) <winford@object.stream> | ||
| %% All rights reserved. | ||
| %% | ||
| %% This is part of atomvm_spectrometer | ||
| %% | ||
| %% SPDX-FileCopyrightText: 2026 Winford (UncleGrumpy) <winford@object.stream> | ||
| %% SPDX-License-Identifier: Apache-2.0 | ||
| %% | ||
|
|
||
| -module(spectrometer_elixir_tests). | ||
| -include_lib("eunit/include/eunit.hrl"). | ||
|
|
||
| %% ============================================================================= | ||
| %% parse_query_string/1 tests - 8 formats for Elixir.GPIO:digital_read/1 | ||
| %% ============================================================================= | ||
|
|
||
| parse_query_8_formats_test() -> | ||
| FormatsWithArity = [ | ||
| {"Elixir.GPIO.digital_read/1", {ok, 'Elixir.GPIO', digital_read, 1}}, | ||
| {"GPIO.digital_read/1", {ok, 'Elixir.GPIO', digital_read, 1}}, | ||
| {"Elixir.GPIO:digital_read/1", {ok, 'Elixir.GPIO', digital_read, 1}}, | ||
| {"GPIO:digital_read/1", {ok, 'Elixir.GPIO', digital_read, 1}} | ||
| ], | ||
| FormatsNoArity = [ | ||
| {"Elixir.GPIO.digital_read", {ok, 'Elixir.GPIO', digital_read}}, | ||
| {"GPIO.digital_read", {ok, 'Elixir.GPIO', digital_read}}, | ||
| {"Elixir.GPIO:digital_read", {ok, 'Elixir.GPIO', digital_read}}, | ||
| {"GPIO:digital_read", {ok, 'Elixir.GPIO', digital_read}} | ||
| ], | ||
| lists:foreach( | ||
| fun({Format, Expected}) -> | ||
| Result = spectrometer_atomvm:parse_query_string(Format), | ||
| ?assertEqual(Expected, Result) | ||
| end, | ||
| FormatsWithArity ++ FormatsNoArity | ||
| ). | ||
|
|
||
| %% ============================================================================= | ||
| %% normalize_module tests | ||
| %% ============================================================================= | ||
|
|
||
| normalize_gpio_test() -> | ||
| ?assertEqual( | ||
| 'GPIO', | ||
| spectrometer_utils:normalize_module_name("GPIO") | ||
| ). | ||
|
|
||
| normalize_elixir_gpio_test() -> | ||
| ?assertEqual( | ||
| 'Elixir.GPIO', | ||
| spectrometer_utils:normalize_module_name("Elixir.GPIO") | ||
| ). | ||
|
|
||
| normalize_lists_test() -> | ||
| ?assertEqual( | ||
| lists, | ||
| spectrometer_utils:normalize_module_name("lists") | ||
| ). | ||
|
|
||
| normalize_with_flag_test() -> | ||
| ?assertEqual( | ||
| 'Elixir.GPIO', | ||
| spectrometer_utils:normalize_module_name("GPIO", true) | ||
| ), | ||
| ?assertEqual( | ||
| 'GPIO', | ||
| spectrometer_utils:normalize_module_name("GPIO", false) | ||
| ). | ||
|
|
||
| %% ============================================================================= | ||
| %% is_elixir_module_name tests | ||
| %% ============================================================================= | ||
|
|
||
| is_elixir_module_name_elxir_prefix_test() -> | ||
| ?assertEqual(true, spectrometer_utils:is_elixir_module_name("Elixir.GPIO")), | ||
| ?assertEqual( | ||
| true, spectrometer_utils:is_elixir_module_name("Elixir.MyModule") | ||
| ). | ||
|
|
||
| is_elixir_module_name_lowercase_test() -> | ||
| ?assertEqual(false, spectrometer_utils:is_elixir_module_name("lists")), | ||
| ?assertEqual(false, spectrometer_utils:is_elixir_module_name("maps")), | ||
| % Uppercase without Elixir prefix is no longer considered Elixir | ||
| ?assertEqual(false, spectrometer_utils:is_elixir_module_name("GPIO")), | ||
| ?assertEqual(false, spectrometer_utils:is_elixir_module_name("MyModule")). | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| {ok, 'Elixir.MapSet', new, 0}, | ||
| spectrometer_atomvm:parse_query_string("Elixir.MapSet:new/0") | ||
| ). | ||
|
|
||
| %% ============================================================================= | ||
| %% filter_modules_by_type/2 tests (new function in this PR) | ||
| %% ============================================================================= | ||
|
|
||
| filter_modules_by_type_erlang_only_test() -> | ||
| Mods = [lists, maps, 'Elixir.GPIO', 'Elixir.Enum', erlang, gen_server], | ||
| Result = spectrometer_atomvm:filter_modules_by_type(Mods, erlang_only), | ||
| ?assertEqual([lists, maps, erlang, gen_server], Result), | ||
| % All Elixir modules are removed | ||
| ?assertNot(lists:member('Elixir.GPIO', Result)), | ||
| ?assertNot(lists:member('Elixir.Enum', Result)). | ||
|
|
||
| filter_modules_by_type_elixir_only_test() -> | ||
| Mods = [lists, maps, 'Elixir.GPIO', 'Elixir.Enum', erlang, 'Elixir.List'], | ||
| Result = spectrometer_atomvm:filter_modules_by_type(Mods, elixir_only), | ||
| ?assertEqual(['Elixir.GPIO', 'Elixir.Enum', 'Elixir.List'], Result), | ||
| % All Erlang modules are removed | ||
| ?assertNot(lists:member(lists, Result)), | ||
| ?assertNot(lists:member(erlang, Result)). | ||
|
|
||
| filter_modules_by_type_undefined_test() -> | ||
| Mods = [lists, 'Elixir.GPIO', erlang], | ||
| % undefined filter returns all modules unchanged | ||
| ?assertEqual(Mods, spectrometer_atomvm:filter_modules_by_type(Mods, undefined)). | ||
|
|
||
| filter_modules_by_type_empty_list_test() -> | ||
| % Empty list stays empty regardless of filter | ||
| ?assertEqual([], spectrometer_atomvm:filter_modules_by_type([], erlang_only)), | ||
| ?assertEqual([], spectrometer_atomvm:filter_modules_by_type([], elixir_only)), | ||
| ?assertEqual([], spectrometer_atomvm:filter_modules_by_type([], undefined)). | ||
|
|
||
| filter_modules_by_type_all_elixir_with_erlang_filter_test() -> | ||
| % All Elixir modules filtered by erlang_only gives empty list | ||
| Mods = ['Elixir.GPIO', 'Elixir.Enum', 'Elixir.List'], | ||
| ?assertEqual([], spectrometer_atomvm:filter_modules_by_type(Mods, erlang_only)). | ||
|
|
||
| filter_modules_by_type_all_erlang_with_elixir_filter_test() -> | ||
| % All Erlang modules filtered by elixir_only gives empty list | ||
| Mods = [lists, maps, erlang, gen_server], | ||
| ?assertEqual([], spectrometer_atomvm:filter_modules_by_type(Mods, elixir_only)). | ||
|
|
||
| %% ============================================================================= | ||
| %% format_since/1 tests (function exists in this PR's scope) | ||
| %% ============================================================================= | ||
|
|
||
| format_since_version_binary_test() -> | ||
| % Binary version string is returned as a string | ||
| ?assertEqual("v0.5.0", spectrometer_atomvm:format_since(<<"v0.5.0">>)), | ||
| ?assertEqual("v0.7.0", spectrometer_atomvm:format_since(<<"v0.7.0">>)). | ||
|
|
||
| format_since_unreleased_test() -> | ||
| % Unreleased tuple formats as "unreleased BRANCH" | ||
| ?assertEqual( | ||
| "unreleased main", | ||
| spectrometer_atomvm:format_since({unreleased, <<"main">>}) | ||
| ), | ||
| ?assertEqual( | ||
| "unreleased 0.7.x", | ||
| spectrometer_atomvm:format_since({unreleased, <<"0.7.x">>}) | ||
| ). | ||
|
|
||
| format_since_unknown_test() -> | ||
| % Special case: <<"unknown">> returns the string "unknown" | ||
| ?assertEqual("unknown", spectrometer_atomvm:format_since(<<"unknown">>)). | ||
|
|
||
| format_since_other_binary_test() -> | ||
| % Any other binary is returned as string | ||
| ?assertEqual( | ||
| "some_branch", | ||
| spectrometer_atomvm:format_since(<<"some_branch">>) | ||
| ). | ||
|
|
||
| %% ============================================================================= | ||
| %% Regression test: supported_modules includes Elixir modules from bundled data | ||
| %% ============================================================================= | ||
|
|
||
| supported_modules_includes_elixir_test() -> | ||
| % The bundled data (updated in this PR) contains Elixir modules | ||
| % Verify that supported_modules/0 returns a mix of Elixir and Erlang modules | ||
| Mods = spectrometer_atomvm:supported_modules(), | ||
| ElixirMods = spectrometer_atomvm:filter_modules_by_type(Mods, elixir_only), | ||
| ErlangMods = spectrometer_atomvm:filter_modules_by_type(Mods, erlang_only), | ||
| % After this PR, we should have at least some Elixir modules | ||
| ?assert(is_list(ElixirMods)), | ||
| ?assert(is_list(ErlangMods)), | ||
| % Total count should match | ||
| ?assertEqual(length(Mods), length(ElixirMods) + length(ErlangMods)). | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a empty newline at the end of the file |
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should only be one empty line between tests.