From b52519437fa214624f6a85debcfefc79e032294f Mon Sep 17 00:00:00 2001 From: Carlos Mateus Date: Sun, 16 Jun 2024 16:26:57 +0200 Subject: Add feature to suggest similar tasks when a task is not found (#78) * Add feature to suggest similar tasks when a task is not found * Add test for feature to suggest similar tasks when a task is not found * Add a test for when a task is not found and there are no suggestions * Fix lint --- .../fixtures/project_with_tasks_suggestion/pyproject.toml | 7 +++++++ tests/test_taskipy.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/fixtures/project_with_tasks_suggestion/pyproject.toml (limited to 'tests') diff --git a/tests/fixtures/project_with_tasks_suggestion/pyproject.toml b/tests/fixtures/project_with_tasks_suggestion/pyproject.toml new file mode 100644 index 0000000..302e388 --- /dev/null +++ b/tests/fixtures/project_with_tasks_suggestion/pyproject.toml @@ -0,0 +1,7 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" + +[tool.taskipy.tasks] +exit_17 = "exit 17" +print_hello_stdout = "echo 'hello stdout'" diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py index a9d0b2c..c8a314f 100644 --- a/tests/test_taskipy.py +++ b/tests/test_taskipy.py @@ -314,6 +314,20 @@ class TaskRunFailTestCase(TaskipyTestCase): self.assertSubstr('could not find task "task_that_does_not_exist"', stdout) self.assertEqual(exit_code, 127) + def test_exiting_with_code_127_and_printing_suggestion_if_task_not_found(self): + cwd = self.create_test_dir_from_fixture('project_with_tasks_suggestion') + exit_code, stdout, _ = self.run_task('stdout', cwd=cwd) + + self.assertSubstr('could not find task "stdout", did you mean "print_hello_stdout"?', stdout) + self.assertEqual(exit_code, 127) + + def test_exiting_with_code_127_and_printing_if_task_not_found_and_suggestion(self): + cwd = self.create_test_dir_from_fixture("project_with_tasks_suggestion") + exit_code, stdout, _ = self.run_task("task_that_does_not_exist", cwd=cwd) + + self.assertEqual('could not find task "task_that_does_not_exist"\n', stdout) + self.assertEqual(exit_code, 127) + def test_exiting_with_code_127_and_printing_if_no_arg_is_passed(self): cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') executable_path = path.abspath('task') -- cgit v1.2.3