colormake 0.1.2

A fast, lightweight tool to colorize make output for better readability.
# ColorMake Test Makefile
# Tests all color functionality in colormake

# Build configuration
CARGO = cargo
TARGET = target/release/colormake
DEBUG_TARGET = target/debug/colormake

# Default target
all: build test-colors

# Build the project
build:
	@echo "Building colormake..."
	$(CARGO) build --release
	@echo "Build complete!"

# Build debug version for testing
build-debug:
	@echo "Building colormake (debug)..."
	$(CARGO) build
	@echo "Debug build complete!"

# Run Rust unit tests
test-unit:
	@echo "Running unit tests..."
	$(CARGO) test
	@echo "Unit tests complete!"

# Test: Show color configuration
test-config:
	@$(TARGET) --show-config || $(DEBUG_TARGET) --show-config

# Test: Color output with make commands
test-make-colors:
	@echo "make[1]: Entering directory '/test'" | $(TARGET) || echo "make[1]: Entering directory '/test'" | $(DEBUG_TARGET)
	@echo "make[1]: Leaving directory '/test'" | $(TARGET) || echo "make[1]: Leaving directory '/test'" | $(DEBUG_TARGET)
	@echo "pmake[2]: Nothing to be done" | $(TARGET) || echo "pmake[2]: Nothing to be done" | $(DEBUG_TARGET)
	@echo "gmake[3]: 'target' is up to date" | $(TARGET) || echo "gmake[3]: 'target' is up to date" | $(DEBUG_TARGET)

# Test: GCC/Compiler command coloring
test-gcc-colors:
	@echo "gcc -c file.c -o file.o" | $(TARGET) || echo "gcc -c file.c -o file.o" | $(DEBUG_TARGET)
	@echo "g++ -std=c++17 main.cpp" | $(TARGET) || echo "g++ -std=c++17 main.cpp" | $(DEBUG_TARGET)
	@echo "clang -Wall -Wextra test.c" | $(TARGET) || echo "clang -Wall -Wextra test.c" | $(DEBUG_TARGET)
	@echo "rustc --edition 2021 src/main.rs" | $(TARGET) || echo "rustc --edition 2021 src/main.rs" | $(DEBUG_TARGET)
	@echo "cargo build --release" | $(TARGET) || echo "cargo build --release" | $(DEBUG_TARGET)
	@echo "CC=gcc make" | $(TARGET) || echo "CC=gcc make" | $(DEBUG_TARGET)

# Test: Error message coloring
test-error-colors:
	@echo "src/main.c:42:5: error: 'x' undeclared" | $(TARGET) || echo "src/main.c:42:5: error: 'x' undeclared" | $(DEBUG_TARGET)
	@echo "file.cpp:10:15: error: expected ';' before '}'" | $(TARGET) || echo "file.cpp:10:15: error: expected ';' before '}'" | $(DEBUG_TARGET)
	@echo "error: cannot find value 'foo' in this scope" | $(TARGET) || echo "error: cannot find value 'foo' in this scope" | $(DEBUG_TARGET)

# Test: Warning message coloring
test-warning-colors:
	@echo "src/main.c:10:5: warning: unused variable 'x'" | $(TARGET) || echo "src/main.c:10:5: warning: unused variable 'x'" | $(DEBUG_TARGET)
	@echo "file.cpp:20: warning: comparison of integers of different signs" | $(TARGET) || echo "file.cpp:20: warning: comparison of integers of different signs" | $(DEBUG_TARGET)
	@echo "warning: function 'foo' is deprecated" | $(TARGET) || echo "warning: function 'foo' is deprecated" | $(DEBUG_TARGET)

# Test: Note message coloring
test-note-colors:
	@echo "src/main.c:10:5: note: declared here" | $(TARGET) || echo "src/main.c:10:5: note: declared here" | $(DEBUG_TARGET)
	@echo "note: in expansion of macro 'FOO'" | $(TARGET) || echo "note: in expansion of macro 'FOO'" | $(DEBUG_TARGET)

# Test: Filename and line number coloring
test-file-colors:
	@echo "src/main.c:42:5: error: test" | $(TARGET) || echo "src/main.c:42:5: error: test" | $(DEBUG_TARGET)
	@echo "include/header.h:10: warning: test" | $(TARGET) || echo "include/header.h:10: warning: test" | $(DEBUG_TARGET)
	@echo "lib/utils.rs:100: note: test" | $(TARGET) || echo "lib/utils.rs:100: note: test" | $(DEBUG_TARGET)

# Test: No color flag
test-no-color:
	@echo "make[1]: Entering directory" | $(TARGET) --no-color || echo "make[1]: Entering directory" | $(DEBUG_TARGET) --no-color
	@echo "gcc -c file.c" | $(TARGET) --no-color || echo "gcc -c file.c" | $(DEBUG_TARGET) --no-color
	@echo "file.c:10:5: error: test" | $(TARGET) --no-color || echo "file.c:10:5: error: test" | $(DEBUG_TARGET) --no-color

# Test: Column width truncation
test-cols:
	@echo "This is a very long line that should be truncated when cols is set to a small value" | $(TARGET) --cols 50 || echo "This is a very long line that should be truncated when cols is set to a small value" | $(DEBUG_TARGET) --cols 50
	@echo "Another extremely long line with many words that exceeds the column limit" | $(TARGET) --cols 40 || echo "Another extremely long line with many words that exceeds the column limit" | $(DEBUG_TARGET) --cols 40

# Test: Complex make output simulation
test-complex:
	@echo "make[1]: Entering directory '/project/src'" | $(TARGET) || echo "make[1]: Entering directory '/project/src'" | $(DEBUG_TARGET)
	@echo "gcc -Wall -Wextra -O2 -c main.c -o main.o" | $(TARGET) || echo "gcc -Wall -Wextra -O2 -c main.c -o main.o" | $(DEBUG_TARGET)
	@echo "main.c:42:5: error: 'x' undeclared (first use in this function)" | $(TARGET) || echo "main.c:42:5: error: 'x' undeclared (first use in this function)" | $(DEBUG_TARGET)
	@echo "main.c:42:5: note: each undeclared identifier is reported only once" | $(TARGET) || echo "main.c:42:5: note: each undeclared identifier is reported only once" | $(DEBUG_TARGET)
	@echo "main.c:10:5: warning: unused variable 'y'" | $(TARGET) || echo "main.c:10:5: warning: unused variable 'y'" | $(DEBUG_TARGET)
	@echo "make[1]: Leaving directory '/project/src'" | $(TARGET) || echo "make[1]: Leaving directory '/project/src'" | $(DEBUG_TARGET)

# Test: Make command execution (self-test)
test-make-exec:
	@$(TARGET) --make-cmd echo "test" || $(DEBUG_TARGET) --make-cmd echo "test"
	@$(TARGET) --make-cmd echo "make[1]: test output" || $(DEBUG_TARGET) --make-cmd echo "make[1]: test output"

# Test: Libtool output
test-libtool:
	@echo "libtool: compile: gcc -c file.c" | $(TARGET) || echo "libtool: compile: gcc -c file.c" | $(DEBUG_TARGET)
	@echo "libtool: link: gcc -o program file.o" | $(TARGET) || echo "libtool: link: gcc -o program file.o" | $(DEBUG_TARGET)

# Test: Multiple line input
test-multiline:
	@printf "make[1]: Entering directory\nmake[2]: Building target\ngcc -c file.c\nfile.c:10:5: error: test\nmake[2]: Leaving directory\n" | $(TARGET) || printf "make[1]: Entering directory\nmake[2]: Building target\ngcc -c file.c\nfile.c:10:5: error: test\nmake[2]: Leaving directory\n" | $(DEBUG_TARGET)

# Run all color tests
test-colors: test-config test-make-colors test-gcc-colors test-error-colors \
             test-warning-colors test-note-colors test-file-colors test-no-color \
             test-cols test-complex test-make-exec test-libtool test-multiline
	@echo ""
	@echo "=== All color tests complete! ==="

# Run all tests (unit + color)
test: test-unit test-colors
	@echo ""
	@echo "=== All tests complete! ==="

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	$(CARGO) clean
	@echo "Clean complete!"

# Install (requires root)
install: build
	@echo "Installing colormake..."
	install -m 755 $(TARGET) /usr/local/bin/colormake
	@echo "Installation complete!"

# Uninstall
uninstall:
	@echo "Uninstalling colormake..."
	rm -f /usr/local/bin/colormake
	@echo "Uninstallation complete!"

# Help target
help:
	@echo "ColorMake Test Makefile"
	@echo ""
	@echo "Available targets:"
	@echo "  build          - Build release version"
	@echo "  build-debug    - Build debug version"
	@echo "  test-unit      - Run Rust unit tests"
	@echo "  test-config    - Test --show-config"
	@echo "  test-make-colors    - Test make command coloring"
	@echo "  test-gcc-colors     - Test GCC/compiler coloring"
	@echo "  test-error-colors   - Test error message coloring"
	@echo "  test-warning-colors - Test warning message coloring"
	@echo "  test-note-colors    - Test note message coloring"
	@echo "  test-file-colors    - Test filename/line number coloring"
	@echo "  test-no-color       - Test --no-color flag"
	@echo "  test-cols           - Test column width truncation"
	@echo "  test-complex        - Test complex make output"
	@echo "  test-make-exec      - Test make command execution"
	@echo "  test-libtool        - Test libtool output"
	@echo "  test-multiline      - Test multiline input"
	@echo "  test-colors         - Run all color tests"
	@echo "  test               - Run all tests (unit + color)"
	@echo "  clean              - Clean build artifacts"
	@echo "  install            - Install colormake (requires root)"
	@echo "  uninstall          - Uninstall colormake"
	@echo "  help               - Show this help message"
	@echo ""
	@echo "Default target: build + test-colors"

.PHONY: all build build-debug test-unit test-config test-make-colors \
        test-gcc-colors test-error-colors test-warning-colors test-note-colors \
        test-file-colors test-no-color test-cols test-complex test-make-exec \
        test-libtool test-multiline test-colors test clean install uninstall help