Skip to content

Commit

Permalink
Break dependencies between *Test classes by pulling shared code into …
Browse files Browse the repository at this point in the history
…separate utility classes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158205798
  • Loading branch information
shicks authored and brad4d committed Jun 7, 2017
1 parent 3f0bd9f commit 084fc27
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 35 deletions.
36 changes: 2 additions & 34 deletions test/com/google/javascript/jscomp/Es6RewriteModulesTest.java
Expand Up @@ -66,45 +66,13 @@ protected int getNumRepetitions() {
return 1;
}

static void testModules(CompilerTestCase test, String input, String expected) {
// Shared with ProcessCommonJSModulesTest.
String fileName = test.getFilename() + ".js";
ImmutableList<SourceFile> inputs =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode("yet_another.js", "goog.provide('module$yet_another');"),
SourceFile.fromCode(fileName, input));
ImmutableList<SourceFile> expecteds =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode("yet_another.js", "goog.provide('module$yet_another');"),
SourceFile.fromCode(fileName, expected));
test.test(inputs, expecteds);
}

static void testModules(
CompilerTestCase test, ImmutableList<SourceFile> inputs, String expected) {
ImmutableList<SourceFile> expecteds =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode(test.getFilename() + ".js", expected));
test.test(inputs, expecteds);
}

void testModules(String input, String expected) {
testModules(this, input,
ModulesTestUtils.testModules(this, input,
"/** @fileoverview\n * @suppress {missingProvide|missingRequire}\n */" + expected);
}

private static void testModules(CompilerTestCase test, String input, DiagnosticType error) {
String fileName = test.getFilename() + ".js";
ImmutableList<SourceFile> inputs =
ImmutableList.of(SourceFile.fromCode("other.js", ""), SourceFile.fromCode(fileName, input));
test.test(inputs, null, error);
}

private void testModules(String input, DiagnosticType error) {
testModules(this, input, error);
ModulesTestUtils.testModules(this, input, error);
}

public void testImport() {
Expand Down
58 changes: 58 additions & 0 deletions test/com/google/javascript/jscomp/ModulesTestUtils.java
@@ -0,0 +1,58 @@
/*
* Copyright 2017 The Closure Compiler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.javascript.jscomp;

import com.google.common.collect.ImmutableList;

/**
* Test utilities for testing modules, used by {@link Es6RewriteModulesTest}
* and {@link ProcessCommonJSModulesTest}.
*/
class ModulesTestUtils {

static void testModules(CompilerTestCase test, String input, String expected) {
// Shared with ProcessCommonJSModulesTest.
String fileName = test.getFilename() + ".js";
ImmutableList<SourceFile> inputs =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode("yet_another.js", "goog.provide('module$yet_another');"),
SourceFile.fromCode(fileName, input));
ImmutableList<SourceFile> expecteds =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode("yet_another.js", "goog.provide('module$yet_another');"),
SourceFile.fromCode(fileName, expected));
test.test(inputs, expecteds);
}

static void testModules(
CompilerTestCase test, ImmutableList<SourceFile> inputs, String expected) {
ImmutableList<SourceFile> expecteds =
ImmutableList.of(
SourceFile.fromCode("other.js", "goog.provide('module$other');"),
SourceFile.fromCode(test.getFilename() + ".js", expected));
test.test(inputs, expecteds);
}

static void testModules(CompilerTestCase test, String input, DiagnosticType error) {
String fileName = test.getFilename() + ".js";
ImmutableList<SourceFile> inputs =
ImmutableList.of(SourceFile.fromCode("other.js", ""), SourceFile.fromCode(fileName, input));
test.test(inputs, null, error);
}
}
Expand Up @@ -56,7 +56,7 @@ protected int getNumRepetitions() {
}

void testModules(String input, String expected) {
Es6RewriteModulesTest.testModules(this, input, expected);
ModulesTestUtils.testModules(this, input, expected);
}

public void testWithoutExports() {
Expand Down

0 comments on commit 084fc27

Please sign in to comment.