TSultanov commented on code in PR #24874:
URL: https://github.com/apache/beam/pull/24874#discussion_r1148954284


##########
playground/backend/internal/fs_tool/java_fs_test.go:
##########
@@ -142,36 +184,159 @@ func Test_executableName(t *testing.T) {
                        // Test case with calling sourceFileName method with 
multiple files where one of them is main
                        // As a result, want to receive a name that should be 
executed
                        name: "Multiple files where one of them is main",
-                       prepare: func() {
+                       prepare: func() error {
                                compiled := filepath.Join(workDir, 
pipelinesFolder, pipelineId.String(), compiledFolderName)
-                               secondaryFilePath := filepath.Join(compiled, 
"temp.scala")
-                               err := os.WriteFile(secondaryFilePath, 
[]byte("TEMP_DATA"), 0600)
+                               primaryFilePath := filepath.Join(compiled, 
"main.scala")
+                               err := os.WriteFile(primaryFilePath, 
[]byte("object MinimalWordCount {def main(cmdlineArgs: Array[String]): Unit = 
{}}"), 0600)
                                if err != nil {
-                                       panic(err)
+                                       return err
                                }
-                               primaryFilePath := filepath.Join(compiled, 
"main.scala")
-                               err = os.WriteFile(primaryFilePath, 
[]byte("object MinimalWordCount {def main(cmdlineArgs: Array[String]): Unit = 
{}}"), 0600)
+                               secondaryFilePath := filepath.Join(compiled, 
"temp.scala")
+                               err = os.WriteFile(secondaryFilePath, 
[]byte("TEMP_DATA"), 0600)
                                if err != nil {
-                                       panic(err)
+                                       return err
                                }
+                               return nil
                        },
+                       cleanup: cleanupFunc,
                        args: args{
                                executableFolder: filepath.Join(workDir, 
pipelinesFolder, pipelineId.String(), "bin"),
                        },
                        want:    "main",
                        wantErr: false,
                },
+               {
+                       // Test case with calling sourceFileName method with 
multiple files where one of them is a .class file
+                       // with main() method
+                       // As a result, want to receive a name that should be 
executed
+                       name: "Multiple Java class files where one of them 
contains main",
+                       prepare: func() error {
+                               testdataPath := "java_testdata"
+                               sourceFile := filepath.Join(testdataPath, 
"HasMainTest1.java")
+
+                               err := compileJavaFiles(sourceFile)

Review Comment:
   @damccorm the `.java` file we are passing here contains multiple classes, so 
Java compiler will produce several `.class` files.
   Yes, this is confusing, and this is the reason why we need to have this 
convoluted method of finding what .class file is executable as there is no 
direct correspondence between input and output file names in Java compiler.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to