Skip to content

Commit 5b99a5f

Browse files
add it test for discovery
1 parent 2cad015 commit 5b99a5f

File tree

6 files changed

+143
-1
lines changed

6 files changed

+143
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* A simple Java class to test config discovery functionality.
3+
*/
4+
public class Sample {
5+
6+
public static void main(String[] args) {
7+
helloWorld();
8+
int result = addNumbers(5, 3);
9+
System.out.println("5 + 3 = " + result);
10+
}
11+
12+
public static void helloWorld() {
13+
System.out.println("Hello, World!");
14+
}
15+
16+
public static int addNumbers(int a, int b) {
17+
return a + b;
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mode: local
2+
runtimes:
3+
4+
5+
6+
7+
tools:
8+
9+
10+
11+
12+
13+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// A simple Dart file to test config discovery functionality.
2+
3+
void main() {
4+
helloWorld();
5+
final result = addNumbers(5, 3);
6+
print('5 + 3 = $result');
7+
}
8+
9+
void helloWorld() {
10+
print('Hello, World!');
11+
}
12+
13+
int addNumbers(int a, int b) {
14+
return a + b;
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* A simple JavaScript file to test config discovery functionality.
3+
*/
4+
5+
function helloWorld() {
6+
console.log("Hello, World!");
7+
}
8+
9+
function addNumbers(a, b) {
10+
return a + b;
11+
}
12+
13+
// Usage
14+
helloWorld();
15+
const result = addNumbers(5, 3);
16+
console.log(`5 + 3 = ${result}`);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
"""
3+
A simple Python file to test config discovery functionality.
4+
"""
5+
6+
def hello_world():
7+
"""Print hello world message."""
8+
print("Hello, World!")
9+
10+
def add_numbers(a, b):
11+
"""Add two numbers and return the result."""
12+
return a + b
13+
14+
if __name__ == "__main__":
15+
hello_world()
16+
result = add_numbers(5, 3)
17+
print(f"5 + 3 = {result}")

integration-tests/run.sh

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
503562
echo "Starting integration tests..."
504563
echo "----------------------------------------"
505564

@@ -509,5 +568,8 @@ run_init_test "$SCRIPT_DIR/init-without-token" "init-without-token" "false"
509568
# Test 2: Init with token
510569
run_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+
512574
echo "All tests completed successfully! 🎉"
513575

0 commit comments

Comments
 (0)