feat: fn index extrae unit_tests automáticamente
El indexer lee test_file_path de funciones testeadas, parsea los test cases y los inserta en unit_tests. El output de fn index ahora muestra el conteo de unit_tests extraídos.
This commit is contained in:
+1
-1
@@ -123,7 +123,7 @@ func cmdIndex() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Indexed %d functions, %d types, %d apps, %d analysis\n", result.Functions, result.Types, result.Apps, result.Analysis)
|
fmt.Printf("Indexed %d functions, %d types, %d apps, %d analysis, %d unit_tests\n", result.Functions, result.Types, result.Apps, result.Analysis, result.UnitTests)
|
||||||
for _, e := range result.ValidationErrors {
|
for _, e := range result.ValidationErrors {
|
||||||
fmt.Fprintf(os.Stderr, " INVALID: %s\n", e)
|
fmt.Fprintf(os.Stderr, " INVALID: %s\n", e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type IndexResult struct {
|
|||||||
Types int
|
Types int
|
||||||
Apps int
|
Apps int
|
||||||
Analysis int
|
Analysis int
|
||||||
|
UnitTests int
|
||||||
ValidationErrors []string
|
ValidationErrors []string
|
||||||
Warnings []string
|
Warnings []string
|
||||||
Errors []string
|
Errors []string
|
||||||
@@ -203,6 +204,39 @@ func Index(db *DB, root string) (*IndexResult, error) {
|
|||||||
result.Analysis++
|
result.Analysis++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract unit tests from test files of tested functions
|
||||||
|
if err := db.PurgeUnitTests(); err != nil {
|
||||||
|
result.Warnings = append(result.Warnings, fmt.Sprintf("purging unit_tests: %v", err))
|
||||||
|
}
|
||||||
|
for _, f := range functions {
|
||||||
|
if !f.Tested || f.TestFilePath == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
absTestPath := filepath.Join(root, f.TestFilePath)
|
||||||
|
cases, err := parseTestFile(absTestPath, f.Lang)
|
||||||
|
if err != nil {
|
||||||
|
result.Warnings = append(result.Warnings, fmt.Sprintf("%s: parsing tests: %v", f.ID, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i, tc := range cases {
|
||||||
|
ut := &UnitTest{
|
||||||
|
ID: fmt.Sprintf("%s_t%d", f.ID, i),
|
||||||
|
FunctionID: f.ID,
|
||||||
|
Name: tc.Name,
|
||||||
|
Code: tc.Code,
|
||||||
|
FilePath: f.TestFilePath,
|
||||||
|
Lang: f.Lang,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
if err := db.InsertUnitTest(ut); err != nil {
|
||||||
|
result.Warnings = append(result.Warnings, fmt.Sprintf("insert unit_test %s: %v", ut.ID, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result.UnitTests++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Post-insert: warn about file_path entries that don't exist on disk
|
// Post-insert: warn about file_path entries that don't exist on disk
|
||||||
for _, f := range functions {
|
for _, f := range functions {
|
||||||
if f.FilePath != "" {
|
if f.FilePath != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user