forked from yohasebe/code-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-code-packager.sh
More file actions
executable file
·117 lines (100 loc) · 4.05 KB
/
test-code-packager.sh
File metadata and controls
executable file
·117 lines (100 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Test script for code-packager
# Function to run the code-packager with given options and compare the output
run_test() {
local test_name="$1"
local options="$2"
local expected_output_pattern="$3"
echo "Running test: $test_name"
output=$(./code-packager $options 2>&1)
if [[ "$output" =~ $expected_output_pattern ]]; then
echo "Test passed: $test_name"
else
echo "Test failed: $test_name"
echo "Expected output pattern:"
echo "$expected_output_pattern"
echo "Actual output:"
echo "$output"
fi
echo "------------------------"
}
# Function to validate JSON structure
validate_json() {
local json_file="$1"
if ! jq empty "$json_file" > /dev/null; then
echo "Error: Invalid JSON structure in '$json_file'."
exit 1
fi
}
# Get the current directory
current_dir=$(pwd)
# Test case 1: Including multiple file types
test_include_multiple_types() {
local options="-t $current_dir -o code.json -i .sh -i .md -s 2048 -z 1"
local expected_output_pattern=$'Output file zipped: code.zip\nJSON output saved to: code.json\nDirectory tree:'
run_test "Including multiple file types" "$options" "$expected_output_pattern"
validate_json "code.json"
}
# Test case 2: Excluding specific file types (without inclusion)
test_exclude_specific_types() {
local options="-t $current_dir -o code.json -e .txt -e .md -d 1"
local expected_output_pattern=$'JSON output saved to: code.json\nDirectory tree:'
run_test "Excluding specific file types (without inclusion)" "$options" "$expected_output_pattern"
validate_json "code.json"
}
# Test case 3: Packaging all file types
test_package_all_types() {
local options="-t $current_dir -o code.json -s 10240 -g 0"
local expected_output_pattern=$'JSON output saved to: code.json\nDirectory tree:'
run_test "Packaging all file types" "$options" "$expected_output_pattern"
validate_json "code.json"
}
# Test case 4: Missing required parameters
test_missing_parameters() {
local options=""
local expected_output_pattern=$'Directory path is required.\nUsage: ./code-packager -t <directory_path> -o <output_file> \[options\]'
run_test "Missing required parameters" "$options" "$expected_output_pattern"
}
# Test case 5: Displaying version information
test_version_info() {
local options="-v"
local expected_output_pattern="Code Packager for Language Models - Version"
run_test "Displaying version information" "$options" "$expected_output_pattern"
}
# Test case 6: Displaying help information
test_help_info() {
local options="-h"
local expected_output_pattern="Usage: ./code-packager -t <directory_path> -o <output_file> \[options\]"
run_test "Displaying help information" "$options" "$expected_output_pattern"
}
# Test case 7: Empty directory
test_empty_dir() {
local temp_dir=$(mktemp -d)
local options="-t $temp_dir -o empty_dir.json"
local expected_output_pattern=$'JSON output saved to: empty_dir.json\nDirectory tree:'
run_test "Empty directory" "$options" "$expected_output_pattern"
validate_json "empty_dir.json"
rm -rf "$temp_dir" # Cleanup
}
# Test case 8: Respecting .gitignore
test_gitignore() {
local temp_dir=$(mktemp -d)
touch "$temp_dir/.gitignore"
echo "ignored.txt" > "$temp_dir/.gitignore"
local options="-t $temp_dir -o gitignore_test.json"
local expected_output_pattern=$'JSON output saved to: gitignore_test.json\nDirectory tree:'
run_test "Respecting .gitignore" "$options" "$expected_output_pattern"
validate_json "gitignore_test.json"
rm -rf "$temp_dir" # Cleanup
}
# Test case 9: Invalid input option
test_invalid_option() {
local options="-t . -o output.json -x invalid_option"
local expected_output_pattern="^.*: illegal option -- x"
run_test "Invalid input option" "$options" "$expected_output_pattern"
}
# Test case 10: Output directory specified
test_output_directory() {
local temp_dir=$(mktemp -d)
local options="-t $current_dir -o $temp_dir"
local expected_output_pattern=$'JSON output saved to: '