Skip to content

Commit f961bc3

Browse files
committed
Clean PR
1 parent 5e3f889 commit f961bc3

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

.circleci/collect_results.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ do
2626
AGGREGATED_FILE_NAME=$(echo "$RESULT_XML_FILE" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
2727
echo -n " as $AGGREGATED_FILE_NAME"
2828
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
29-
# Extract source file from system-out and use as the file attribute for each test case
30-
# path=$(grep -oP '(?<=path: ).*' "$RESULT_XML_FILE" | tail -n 1)
31-
# testClassName=$(grep -oP '(?<=testClassName: ).*' "$RESULT_XML_FILE" | tail -n 1)
32-
# escapedPath=$(echo "$path" | sed 's/[\/&]/\\&/g')
33-
# escapedClassName=$(echo "$testClassName" | sed 's/[\/&]/\\&/g')
34-
# sed -i "/<testcase/ s/\(classname=\"$escapedClassName\".*\)/\1 file=\"$escapedPath\"/" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
35-
# sed -i '/<system-out>/,/<\/system-out>/d' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
3629
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
3730
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
3831
# Replace random port numbers by marker in testcase XML nodes to get stable test names

components/context/src/test/java/datadog/context/ContextKeyTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
67
import static org.junit.jupiter.api.Assertions.assertNull;
78
import static org.junit.jupiter.api.Assertions.assertTrue;
89

@@ -17,8 +18,8 @@ class ContextKeyTest {
1718
@ValueSource(strings = {"key"})
1819
void testConstructor(String name) {
1920
ContextKey<String> key = ContextKey.named(name);
20-
System.out.println("*test fails*");
21-
assertNull(key, "created key should not be null");
21+
assertNotNull(key, "created key should not be null");
22+
// assertEquals fails. remove '+ "X"' to fix.
2223
assertEquals(name, key.toString() + "X", name + " label should be supported");
2324
}
2425

components/context/src/test/java/datadog/context/GatherSourceFileInfoExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static Map<String, String> getSourceFiles() {
1919
}
2020

2121
private static void getTestData(ExtensionContext context) {
22-
// get test class name and source file
22+
// get test classname and source file
2323
String testClassName = context.getTestClass().get().getName();
2424
String testClassPath = testClassName.replace(".", "/") + ".java";
2525
String absolutePath = Paths.get("").toAbsolutePath() + "/src/test/java/" + testClassPath;

components/context/src/test/java/datadog/context/InsertSourceFileExtension.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.BufferedWriter;
44
import java.io.FileWriter;
55
import java.nio.file.Files;
6-
import java.nio.file.Path;
76
import java.nio.file.Paths;
87
import java.util.Map;
98
import java.util.regex.Matcher;
@@ -14,32 +13,32 @@
1413
import org.junit.platform.launcher.TestPlan;
1514

1615
public class InsertSourceFileExtension implements TestExecutionListener {
16+
@Override
1717
public void executionStarted(TestIdentifier testIdentifier) {
18-
System.out.println("EXECUTIONSTARTED.");
18+
System.out.println(testIdentifier.getDisplayName() + " test started.");
1919
}
2020

21+
@Override
2122
public void testPlanExecutionStarted(TestPlan testPlan) {
22-
System.out.println("TESTPLANEXECUTIONSTARTED.");
23+
// does not print when tested locally
24+
System.out.println("---testPlanExecutionStarted---");
2325
}
2426

27+
@Override
2528
public void executionFinished(
2629
TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
27-
// should this happen in testPlanExecutionFinished after all tests are run?
28-
30+
// get mapping of test classname to source file
2931
Map<String, String> sourceFiles = GatherSourceFileInfoExtension.getSourceFiles();
3032

31-
// for each test
33+
// for each test...
3234
for (String sourceFile : sourceFiles.keySet()) {
33-
String pathString =
34-
Paths.get("").toAbsolutePath() + "/build/test-results/test/TEST-" + sourceFile + ".xml";
35-
3635
// get xml report file
37-
Path filePath = Paths.get(pathString);
36+
String filePath =
37+
Paths.get("").toAbsolutePath() + "/build/test-results/test/TEST-" + sourceFile + ".xml";
3838
try {
39-
String fileContent = new String(Files.readAllBytes(filePath));
39+
String fileContent = new String(Files.readAllBytes(Paths.get(filePath)));
4040

41-
// modify report with test source file info
42-
// use regex pattern to get class name
41+
// add test source file info to report
4342
Pattern pattern = Pattern.compile("<testcase(.*?)classname=\"(.*?)\"(.*?)>");
4443
Matcher matcher = pattern.matcher(fileContent);
4544
StringBuffer result = new StringBuffer();
@@ -48,11 +47,7 @@ public void executionFinished(
4847
String className = matcher.group(2);
4948
String endAttributes = matcher.group(3);
5049

51-
// add source file attribute
52-
String fileAttribute = "";
53-
if (sourceFiles.containsKey(className)) {
54-
fileAttribute = " file=\"" + sourceFiles.get(className) + "\"";
55-
}
50+
String fileAttribute = " file=\"" + sourceFiles.getOrDefault(className, "") + "\"";
5651
String newTestCase =
5752
"<testcase"
5853
+ begAttributes
@@ -64,24 +59,23 @@ public void executionFinished(
6459
+ ">";
6560
matcher.appendReplacement(result, newTestCase);
6661
}
67-
// add the rest
6862
matcher.appendTail(result);
6963

7064
// set old filePath to new xml result
71-
System.out.println("result: " + result.substring(0, 1000));
72-
73-
// i think this logic gets re-overwritten by xml reports
74-
BufferedWriter writer = new BufferedWriter(new FileWriter(pathString));
65+
// this logic must be wrong or go elsewhere bc its getting overwritten. `result` output
66+
// seems correct.
67+
BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
7568
writer.write(result.toString());
7669
writer.close();
77-
7870
} catch (Exception e) {
7971
System.out.println("Modifying XML files did not work.");
8072
}
8173
}
8274
}
8375

76+
@Override
8477
public void testPlanExecutionFinished(TestPlan testPlan) {
85-
System.out.println("TESTPLANEXECUTIONFINISHED.");
78+
// does not print when tested locally
79+
System.out.println("---testPlanExecutionFinished---.");
8680
}
8781
}

0 commit comments

Comments
 (0)