@@ -499,7 +499,66 @@ run_init_test() {
499499 echo " ----------------------------------------"
500500}
501501
502- # Run both tests
502+ run_config_discover_test () {
503+ local test_dir=" $1 "
504+ local test_name=" $2 "
505+
506+ echo " Running test: $test_name "
507+ [ -d " $test_dir " ] || { echo " ❌ Test directory does not exist: $test_dir " ; exit 1; }
508+
509+ cd " $test_dir " || exit 1
510+ # Clean up previous test results
511+ rm -rf .codacy
512+
513+ # First initialize with basic configuration
514+ " $CLI_PATH " init
515+
516+ # Remove manually all entries from codacy yaml file
517+ # This ensures we test the discover command adding tools to a clean config
518+ local codacy_yaml=" .codacy/codacy.yaml"
519+ if [ -f " $codacy_yaml " ]; then
520+ # Create a minimal codacy.yaml with just the mode
521+ cat > " $codacy_yaml " << 'EOF '
522+ mode: local
523+ tools: []
524+ runtimes: []
525+ EOF
526+ echo " Cleared tools and runtimes from codacy.yaml for discover test"
527+ fi
528+
529+ # Run config discover on the test directory
530+ " $CLI_PATH " config discover sample.dart
531+
532+ # Check dart is in the config
533+ if ! grep -q " dart" .codacy/codacy.yaml; then
534+ echo " ❌ Dart is not in the config"
535+ exit 1
536+ fi
537+
538+ # Discover java
539+ " $CLI_PATH " config discover sample.java
540+
541+ # Check java is in the config
542+ if ! grep -q " java" .codacy/codacy.yaml; then
543+ echo " ❌ Java is not in the config"
544+ exit 1
545+ fi
546+
547+ # check pmd is in the config
548+ if ! grep -q " pmd" .codacy/codacy.yaml; then
549+ echo " ❌ PMD is not in the config"
550+ exit 1
551+ fi
552+
553+ # Run config discover on the test directory - adding all tools
554+ " $CLI_PATH " config discover .
555+
556+ compare_files " expected" " .codacy" " Test $test_name "
557+ echo " ✅ Test $test_name completed successfully"
558+ echo " ----------------------------------------"
559+ }
560+
561+ # Run all tests
503562echo " Starting integration tests..."
504563echo " ----------------------------------------"
505564
@@ -509,5 +568,8 @@ run_init_test "$SCRIPT_DIR/init-without-token" "init-without-token" "false"
509568# Test 2: Init with token
510569run_init_test " $SCRIPT_DIR /init-with-token" " init-with-token" " true"
511570
571+ # Test 3: Config discover
572+ run_config_discover_test " $SCRIPT_DIR /config-discover" " config-discover"
573+
512574echo " All tests completed successfully! 🎉"
513575
0 commit comments