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

Improve CLI test comments #220

Open
Glutexo opened this issue Apr 6, 2024 · 0 comments
Open

Improve CLI test comments #220

Glutexo opened this issue Apr 6, 2024 · 0 comments
Labels

Comments

@Glutexo
Copy link
Owner

Glutexo commented Apr 6, 2024

In the base CLI test it is not entirely clear what’s going on with the working directory. Since there is currently no way to set a working directory, Onigumo defaults to cwd.

It would be possible to set the working directory by File.cd and then use File.write! with a bare file name, removing the need for input_path_tmp = Path.join(tmp_dir, input_path_env). But it would separate the preparation of the environment from the actual run of Onigumo, using the working directory. It may be more correct to explicitly write the files to concrete paths and then run Onigumo with its own path handling rather than change the working directory and then make both Elixir and Onigumo use it.

input_path_env = Application.get_env(:onigumo, :input_path)
input_path_tmp = Path.join(tmp_dir, input_path_env)
input_file_content = InputSupport.url_list(@urls)
File.write!(input_path_tmp, input_file_content)
File.cd(tmp_dir)
Onigumo.CLI.main(["downloader"])

Add comments describing what’s going on, that Onigumo uses the current working directory and why we’re doing the cd here.

Possible solution, changing the working directory first and then using it both by tests and then by Onigumo. Here, we assume the current working directory is the working directory and we operate in that directory even when preparing the test environment.

File.cd(tmp_dir)
input_path = Application.get_env(:onigumo, :input_path)
input_file_content = InputSupport.url_list(@urls)
File.write!(input_path, input_file_content)
Onigumo.CLI.main(["downloader"])

Another solution using comments, changing the working directly right before running onigumo, making explicitly clear what files are we writing where and only testing that Onigumo uses cwd.

# Prepare the test environment by creating a valid URLs file in the wokring directory.
input_path_env = Application.get_env(:onigumo, :input_path)
input_path_tmp = Path.join(tmp_dir, input_path_env)
input_file_content = InputSupport.url_list(@urls)
File.write!(input_path_tmp, input_file_content)

# Onigumo uses cwd as its working directory, cd into that.
File.cd(tmp_dir)
Onigumo.CLI.main(["downloader"])
@Glutexo Glutexo added the cli label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant