[CSM-440]: Add unit tests for component - #1
Open
oykukurtgoz wants to merge 1 commit into
Open
Conversation
- Guard top-level side-effecting code with `if __FILE__ == $PROGRAM_NAME` so main.rb can be required from tests; function definitions stay top level - Replace nil-unsafe ENV access in the JUnit branch (AC_OUTPUT_DIR, AC_ENV_FILE_PATH, HOME) with explicit raises carrying context - Guard run_command against nil/empty commands - Add self-executing test/test_main.rb (rspec + stdlib, no Gemfile): get_env_variable, run_command, ENV validation via Open3 subprocess, composed-command assertions against a fake flutter/tojunit toolchain - Print coverage report at the end of the run - Document `ruby test/test_main.rb` in README Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes CSM-440.
Adds unit tests for
main.rb.The whole PR is 565 added lines and 14 deleted ones;
main.rbaccounts for 25 added and 14 deleted. Nothing in the test logic was reworded — theflutter pub global activate junitreportcommand, thecd … && flutter test …command, thetojunitpipe, theflutter_reportsfolder and the env-file export are byte-for-byte what they were, and the tests pin that.Changes to
main.rbThree, all driven by the issue's prerequisite refactor and its "replace nil-unsafe access with an explicit raise carrying context" requirement.
Top-level side effects are guarded. The three
get_env_variablereads, the JUnit branch, the finalrun_commandandexit 0now sit inside a singleif __FILE__ == $PROGRAM_NAME … endblock, in their original order. The only visible move is that the three variable reads, which used to sit between the two function definitions, now open the guarded block — they had to, since the first one callsabortand would have killed the test process atrequiretime. Appcircle runs the step withruby main.rb, so the guard is true there and the body executes exactly as before.require-ing the file only definesget_env_variableandrun_command.No
begin/rescue LoadErrorguards were needed:main.rbonly requiresopen3,pathnameandfileutils, all stdlib.AC_OUTPUT_DIR,AC_ENV_FILE_PATHandHOMEare validated up front in the JUnit branch.main.rbused to read all three straight fromENV[...]. WithAC_OUTPUT_DIRmissing,File.join(nil, …)raised a bareTypeError; withAC_ENV_FILE_PATHmissing,File.open(nil, 'a')did the same; with either empty, the path silently became/flutter_reportsor''.HOMEwas the worst of the three: missing or empty, the pipe target became/.pub-cache/bin/tojunit,flutter pub global activate junitreportstill ran, and the step only failed when the shell could not findtojunitat the end of the pipe. All three now go throughget_env_variableand raiseMissing <VAR>. …with the reason before anything is written or executed. Before and after, the step fails in those scenarios and exits 1; the difference is that it fails early and says why. Appcircle always sets these variables, so normal runs are unaffected. WhenAC_FLUTTER_JUNIT_REPORTSis notYES, none of the three is required, as before.run_commandrejects a nil or blank command. A one-line guard at the top of the function raisesrun_command: command must not be nil or empty.instead of lettingOpen3.popen3fail with aTypeError/Errno::ENOENT. Neither call site inmain.rbcan pass such a value, so this never triggers in a real run.Tests (
test/test_main.rb)Self-executing, 42 examples, no Gemfile / Bundler —
rspecgem + Ruby stdlib only.ReadableFormatterand the coverage report are reused from CSM-230 / CSM-231.main.rbexposes two functions plus the script as a whole, and the tests cover all three surfaces:get_env_variable, in-process — returns the value when set, returnsnilfor both a missing key and an empty string, works as the left side of|| default, and the|| abort(...)pattern used at the call site raisesSystemExitwith status 1.run_command, in-process — happy path withtrue/echo, the echoed@@[command]line, streamed stdout; nil, empty and whitespace-only commands raise with context and never reachOpen3.popen3; the failure branch raisesRuntimeErrorcarrying the child's stderr and prints that stderr first. Onlytrue,echoandsh -care ever executed.Open3.capture3(env, "ruby #{MAIN_RB}")— a missing and an empty case for each ofAC_FLUTTER_PROJECT_DIR,AC_OUTPUT_DIR,AC_ENV_FILE_PATHandHOME, each asserting exit status 1, theMissing …message on stderr, no write to the env file and no toolchain invocation. One further case asserts that withAC_FLUTTER_JUNIT_REPORTS=NOnone of the three JUnit variables is required.PATHis restricted to a tmpdirbin/holding a fakeflutterthat only records its arguments, and a fake$HOME/.pub-cache/bin/tojunitthat drains stdin. Ten cases assert the exact@@[command]strings for the JUnit and non-JUnit paths, the default--machine, customAC_FLUTTER_TEST_EXTRA_ARGSboth with and without thetojunitpipe, theAC_TEST_RESULT_PATH=…line appended (not overwritten) to the env file, theflutter_reportsfolder being created, the fake log showing exactlyflutter pub global activate junitreport→flutter test --machine→tojunit --output …, and a failingflutter testpropagating as exit 1 with its stderr surfaced.No real toolchain, network, or filesystem writes outside
Dir.mktmpdir. The real Flutter SDK is never onPATHin any subprocess case.Coverage
The number is structural rather than a gap in the tests. Of the 37 executable lines, 22 are the requires and the two function bodies, and those are fully covered in-process. The remaining 15 are the guarded step body: variable reads, JUnit-branch validation, env-file export,
mkdir_pand the tworun_commandcalls. That block only runs in theOpen3subprocesses, which in-processCoveragecannot see — but unlike a Gradle or Xcode step, every one of those lines is executed by the fake-toolchain cases, both the JUnit and the non-JUnit path. Merging subprocess coverage the way CSM-448 does would raise the figure to 100% without adding a test; extracting the command composition into a pure function would too. Both are reasonable follow-ups; neither is in this PR.Docs
README.mdgains a## Running testssection.🤖 Generated with Claude Code