fix: track imports used by forced comptime initializers
This commit is contained in:
@@ -10998,6 +10998,36 @@ unused_import_is_a_warning :: proc(t: ^testing.T) {
|
||||
testing.expect(t, found)
|
||||
}
|
||||
|
||||
@(test)
|
||||
imports_used_only_by_comptime_global_initializers_are_not_warned :: proc(t: ^testing.T) {
|
||||
directory := "/tmp/brolang-test-comptime-global-import"
|
||||
output := "/tmp/brolang-test-comptime-global-import-output"
|
||||
_ = os2.remove_all(directory)
|
||||
defer _ = os2.remove_all(directory)
|
||||
defer _ = os.remove(output)
|
||||
packages := [3]string{"app", "table", "helper"}
|
||||
for name in packages {
|
||||
testing.expect(t, os2.make_directory_all(fmt.tprintf("%s/%s", directory, name)) == nil)
|
||||
}
|
||||
helper_text := `make func() [1]i32 { return [42] }
|
||||
`
|
||||
table_sources := [2]string{
|
||||
"helper :: import \"../helper\"\nvalues :: $helper.make()\n",
|
||||
"helper :: import \"../helper\"\nvalues :: ${ yield helper.make() }\n",
|
||||
}
|
||||
app_text := `table :: import "../table"
|
||||
main func() i32 { return table.values[0] }
|
||||
`
|
||||
testing.expect(t, os.write_entire_file(fmt.tprintf("%s/helper/main.bro", directory), transmute([]byte)helper_text))
|
||||
testing.expect(t, os.write_entire_file(fmt.tprintf("%s/app/main.bro", directory), transmute([]byte)app_text))
|
||||
for table_text in table_sources {
|
||||
testing.expect(t, os.write_entire_file(fmt.tprintf("%s/table/main.bro", directory), transmute([]byte)table_text))
|
||||
testing.expect_value(t, compiler_core.compile_package(fmt.tprintf("%s/app", directory), output), 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 42)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
unused_missing_package_does_not_trap :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-package-missing-unused"
|
||||
|
||||
Reference in New Issue
Block a user