This directory contains a comprehensive test suite for the filetype utility with 290+ test assertions covering file types, editors, and edge cases.
cd tests/
./run_all_tests.shtests/
├── setup_fixtures.sh # Generates 139 test files
├── fixtures/ # Auto-generated test data
│ ├── extensions/ # 80+ files with various extensions
│ ├── shebangs/ # 30+ files with shebang variants
│ ├── binary/ # Binary test files
│ ├── edge_cases/ # Dotfiles, spaces, etc.
│ └── cpp/ # C++ specific tests
├── test_bash.sh # Bash filetype CLI: ~211 assertions
├── test_editcmd.sh # Bash editcmd CLI: ~67 assertions
├── test_library_mode.sh # Test bash library sourcing: ~21 assertions
├── common.sh # Shared test utilities
└── run_all_tests.sh # Master runner
Tests all supported file extensions:
- Shell:
.sh,.bash,.csh,.tcsh - Scripting:
.py,.pl,.rb,.php,.lua,.tcl, etc. - Web:
.js,.ts,.html,.css,.xml,.json - Compiled:
.c,.cpp,.java,.go,.rs,.swift,.scala - Functional:
.hs,.erl,.ex,.lisp,.ml - Data:
.yaml,.ini,.conf,.sql - Other:
.diff,.md,.tex,.r,.prolog, etc.
Tests shebang detection for files without extensions:
#!/bin/bash,#!/usr/bin/env bash,#!/usr/bin/bash#!/bin/sh,#!/usr/bin/env sh- Python, Perl, Ruby, PHP, Node, AWK, Sed, Lua, Tcl variants
Tests all 5 editors with key file types:
- joe: Passthrough (default behavior)
- nano:
js→javascript,md→markdown,diff→patch - vim: JS/MD mappings, bash detection, C++ detection
- emacs:
-modesuffix pattern, special cases (nxml-mode,c++-mode) - vscode:
sh→shellscript, C++ detection
- Version flags, print/dry-run modes
- EDITOR environment variable handling
- Line positioning (-l and +NUM)
- All 5 editor selections
- Syntax detection integration
- Error handling and combined options
- Filenames with spaces, non-existent files
- Dotfiles:
.bashrc,.vimrc,.gitignore - Multiple extensions:
archive.tar.gz,script.min.js - Non-existent files, empty files
- Files with spaces in names
- Binary detection, C++ file detection
- Direct function calls:
filetype(),map_to_editor(),detect_editor_from_env() - Tests bash script when sourced as library
./test_bash.sh # Bash implementation tests
./test_editcmd.sh # Editcmd CLI tests
./test_library_mode.sh # Library mode tests
# Setup fixtures manually
./setup_fixtures.sh======================================================================
FILETYPE - COMPREHENSIVE TEST SUITE
======================================================================
Step 1: Setting up test fixtures
✓ Setup complete: 139 test fixture files created
✓ Fixtures created successfully
Running: Bash Implementation Tests
✓ Bash Implementation Tests PASSED
Running: Editcmd Tests (Bash)
✓ Editcmd Tests (Bash) PASSED
Running: Library Mode Tests (Bash)
✓ Library Mode Tests (Bash) PASSED
======================================================================
FINAL TEST SUMMARY
======================================================================
Test Suites Run: 3
Suites Passed: 3
Suites Failed: 0
Time: 3s
======================================================================
All test suites passed! ✓
- Total Fixtures: 139 test files
- Total Test Assertions: ~299
- Test Suites: 3
- File Types Covered: 47 syntax types
- File Extensions Tested: 80+
- Shebang Variants: 30+
- Editors Tested: 5 (joe, nano, vim, emacs, vscode)
The test suite is designed for CI/CD:
- Exit code 0 on success, non-zero on failure
- Idempotent (can run multiple times)
- Self-contained (generates own fixtures)
- Fast execution (~3-5 seconds total)
- Summary reporting
- Bash tests: Custom assertion framework in
common.sh - Output: Colored PASS/FAIL with TAP-style reporting
- Summary: Total/Pass/Fail counts with ASCII art
To add new tests:
- Add fixtures in
setup_fixtures.sh - Add assertions to
test_bash.sh - Run
./run_all_tests.shto verify
#fin