Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add samples unit test #84

Conversation

AlexanderYastrebov
Copy link
Contributor

This is just a fun excersise, the real validator should use shell script like in #82 since many implementations depend on different jdks and command line arguments.

For #61

This is just a fun excersise, the real validator should use shell
script like in gunnarmorling#82 since many implementations depend on different
jdks and command line arguments.

For gunnarmorling#61
@filiphr
Copy link
Contributor

filiphr commented Jan 4, 2024

Cool idea @AlexanderYastrebov. An alternative for something like this might also be to use Dynamic Tests with a @TestFactory

The classes could be dynamically found. e.g. using CLassGraph

adding dependency

    <dependency>
      <groupId>io.github.classgraph</groupId>
      <artifactId>classgraph</artifactId>
      <version>4.8.165</version>
      <scope>test</scope>
    </dependency>

We can have a test that does something like:

    @TestFactory
    Stream<DynamicTest> testSamples() {
        String pkg = "dev.morling.onebrc";
        try (ScanResult scanResult =
                     new ClassGraph()
                             .enableClassInfo()
                             .acceptPackages(pkg)     // Scan com.xyz and subpackages (omit to scan all packages)
                             .scan()) {               // Start the scan
            return scanResult.getAllClasses()
                    .stream()
                    .filter(classInfo -> classInfo.getSimpleName().startsWith("CalculateAverage"))
                    .map(classInfo -> DynamicTest.dynamicTest(classInfo.getSimpleName(),
                            () -> TestSamples(TestCalculateAverage.class.getClassLoader().loadClass(classInfo.getName()))));
        }
    }

() -> TestSamples(TestCalculateAverage.class.getClassLoader().loadClass(classInfo.getName()))) is calling the test method that is already in there.

Side note, using something like a @TestFactory we could even lookup the calculate_average_<username>.sh files and invoke test.sh.

@gunnarmorling
Copy link
Owner

Do we still need this actually? Feel like the current shell test set-up is good enough for what we need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants