Back to Repositories

Testing Go Run Command Extension Handling in thefuck

This test suite validates the ‘go_run’ rule functionality in thefuck project, focusing on command correction for Go file execution. It ensures proper handling of file extensions when running Go programs through command line.

Test Coverage Overview

The test suite provides comprehensive coverage of the go_run command correction functionality.

Key areas tested include:
  • Command pattern matching for ‘go run’ commands
  • Automatic .go extension addition
  • Multiple input variations handling
Edge cases covered ensure proper handling of different file names while maintaining consistent extension addition.

Implementation Analysis

The testing approach utilizes pytest’s parametrize decorator to implement data-driven testing patterns. This enables efficient testing of multiple input scenarios with minimal code duplication.

Technical implementation features:
  • Parameterized test cases for both matching and command generation
  • Command object usage for input handling
  • Direct assertion patterns for verification

Technical Details

Testing infrastructure includes:
  • pytest framework for test execution
  • Custom Command type implementation
  • Parameterized test decorators
  • Direct assertion patterns
Configuration leverages pytest’s built-in functionality without requiring additional setup.

Best Practices Demonstrated

The test suite exemplifies several testing best practices in Python.

Notable practices include:
  • Separation of matching and command generation tests
  • Data-driven test design
  • Clear test case organization
  • Efficient use of pytest features
  • Consistent assertion patterns

nvbn/thefuck

tests/rules/test_go_run.py

            
import pytest
from thefuck.rules.go_run import match, get_new_command
from thefuck.types import Command


@pytest.mark.parametrize('command', [
    Command('go run foo', ''),
    Command('go run bar', '')])
def test_match(command):
    assert match(command)


@pytest.mark.parametrize('command, new_command', [
    (Command('go run foo', ''), 'go run foo.go'),
    (Command('go run bar', ''), 'go run bar.go')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command