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

Add a "testutils" module and move common test code there #1760

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buildSrc/src/main/groovy/rhino.java-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This file contains Gradle "conventions" that we use in all of our projects.
// It is the appropriate set of conventions to use for modules that will not be
// published, such as test modules.

plugins {
id 'java-library'
id 'com.diffplug.spotless'
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This file inherits from "java-conventions" and adds additional error
// checks and publishing data for modules that will be published to
// Maven Central. It should only be used for those modules that will
// be published and used by other projects.

plugins {
id 'rhino.java-conventions'
id 'maven-publish'
Expand Down
3 changes: 3 additions & 0 deletions rhino/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ plugins {
id 'rhino.library-conventions'
}

dependencies {
testImplementation project(':testutils')
}

publishing {
publications {
Expand Down
87 changes: 0 additions & 87 deletions rhino/src/test/java/org/mozilla/javascript/tests/Utils.java

This file was deleted.

2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'rhino-root'
include 'rhino', 'rhino-engine', 'rhino-tools', 'rhino-xml', 'rhino-all', 'examples', 'tests', 'benchmarks'
include 'rhino', 'rhino-engine', 'rhino-tools', 'rhino-xml', 'rhino-all', 'examples', 'testutils', 'tests', 'benchmarks'
1 change: 1 addition & 0 deletions tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
implementation project(':rhino-tools')
implementation project(':rhino-xml')

testImplementation project(':testutils')
testImplementation("com.tngtech.archunit:archunit-junit4:1.3.0") {
exclude group: 'junit'
}
Expand Down
12 changes: 12 additions & 0 deletions testutils/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This module contains library code used by the tests in multiple other modules.

plugins {
id 'rhino.java-conventions'
}

dependencies {
implementation project(':rhino')
// We need this to be an "implementation" dependency because, in order to be shared
// with tests in other projects, code in here must be in "main".
implementation "junit:junit:4.13.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public class Utils {
/** The default set of levels to run tests at. */
public static final int[] DEFAULT_OPT_LEVELS = new int[] {-1, 9};

/**
* Execute the provided script in a fresh context as "myScript.js".
*
* @param script the script code
*/
static void executeScript(String script, boolean interpreted) {
Utils.runWithMode(
cx -> {
final Scriptable scope = cx.initStandardObjects();
return cx.evaluateString(scope, script, "myScript.js", 1, null);
},
interpreted);
}

/** Runs the action successively with all available optimization levels */
public static void runWithAllOptimizationLevels(final ContextAction<?> action) {
runWithMode(action, false);
Expand All @@ -50,6 +64,7 @@ public static void runWithMode(final ContextAction<?> action, final boolean inte
}

/** Runs the provided action at the given optimization level */
@SuppressWarnings("deprecation")
public static void runWithOptimizationLevel(
final ContextFactory contextFactory,
final ContextAction<?> action,
Expand Down
Loading