Skip to content

Commit

Permalink
JACOBIN-418 Added unit test for classes.go for missing main() method
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Dec 25, 2023
1 parent 8c05df2 commit 1545524
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/classloader/classes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,46 @@ func TestFetchUTF8stringFromCPEntryNumber(t *testing.T) {
_ = wout.Close()
os.Stdout = normalStdout
}

func TestInvalMainMethod(t *testing.T) {
// Testing the changes made as a result of JACOBIN-103
globals.InitGlobals("test")
log.Init()
_ = log.SetLogLevel(log.FINE)

// redirect stderr & stdout to capture results from stderr
normalStderr := os.Stderr
_, w, _ := os.Pipe()
os.Stderr = w

MethArea = &sync.Map{}
k := Klass{
Status: 0,
Loader: "",
Data: &ClData{},
}
k.Data.Name = "testClass"
k.Data.Superclass = "java/lang/Object"
k.Loader = "testloader"
k.Status = 'F'
MethAreaInsert("TestEntry", &k)

// we need a java/lang/Object instance, so just duplicate the entry
// in the MethArea. It's only a placeholder
MethAreaInsert("java/lang/Object", &k)

// fetch a non-existent main() method
_, err := FetchMethodAndCP("java/lan/Object", "main", "([LString;)V")
if err == nil {
t.Errorf("Expecting an err msg for invalid MethAreaFetch of main(), but got none")
}

msg := err.Error()
if !strings.Contains(msg, "main() method not found") {
t.Errorf("TestInvalidLookupOfMethod_Test2: Expecting error of 'main() method not found', got %s", err.Error())
}

// restore stderr and stdout to what they were before
_ = w.Close()
os.Stderr = normalStderr
}

0 comments on commit 1545524

Please sign in to comment.