test/com/google/javascript/jscomp/deps/DepsGeneratorTest.java
/**
   * Ensures that deps files are handled correctly both when listed as deps and when listed as
   * sources.
   */
Ensures that deps files are handled correctly both when listed as deps and when listed as
sources.
Ensures that deps files are handled correctly both when listed as deps and when listed as sources .
@Test
  public void testWithDepsAndSources() throws Exception {
    final SourceFile depsFile1 =
        SourceFile.fromCode(
            "/base/my-project/deps1.js",
            LINE_JOINER.join(
                "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);",
                "goog.addDependency('../prescanned1/file2.js', [], []);",
                "goog.addDependency('../this/is/defined/thrice.js', [], []);",
                "goog.addDependency('../this/is/defined/thrice.js', [], []);",
                ""));
    final SourceFile depsFile2 =
        SourceFile.fromCode(
            "/base/my-project/deps2.js",
            LINE_JOINER.join(
                "goog.addDependency("
                    + "'../prescanned2/file1.js',"
                    + " ['dep.bool', 'dep.number'],"
                    + " ['dep.string']);",
                "goog.addDependency('../prescanned2/file2.js', [], []);",
                "goog.addDependency('../this/is/defined/thrice.js', [], []);",
                ""));
    final SourceFile srcFile1 =
        SourceFile.fromCode(
            "/base/my-project/src1.js",
            LINE_JOINER.join(
                "goog.provide('makejsdeps.file1');",
                "goog.provide('makejsdeps.file1.Test');",
                "",
                "/*",
                "goog.require('failure1)",
                "*/",
                "// goog.require('failure2)",
                "",
                "goog.require('makejsdeps.file2');",
                "goog.require(\"goog\");",
                "goog.require(\"dep.string\");",
                "goog.require(\"dep.number\");",
                ""));
    final SourceFile srcFile2 =
        SourceFile.fromCode("/base/my-project/src2.js", "goog.provide('makejsdeps.file2');");
    String expected =
        LINE_JOINER.join(
            "goog.addDependency("
                + "'../../my-project/src1.js',"
                + " ['makejsdeps.file1', 'makejsdeps.file1.Test'],"
                + " ['makejsdeps.file2', 'dep.string', 'dep.number']);",
            "goog.addDependency('../../my-project/src2.js', ['makejsdeps.file2'], []);",
            "",
            "// Included from: /base/my-project/deps1.js",
            "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);",
            "goog.addDependency('../prescanned1/file2.js', [], []);",
            "",
            "// Included from: /base/my-project/deps2.js",
            "goog.addDependency('../this/is/defined/thrice.js', [], []);",
            "goog.addDependency("
                + "'../prescanned2/file1.js',"
                + " ['dep.bool', 'dep.number'],"
                + " ['dep.string']);",
            "goog.addDependency('../prescanned2/file2.js', [], []);",
            "");
    DepsGenerator depsGenerator =
        new DepsGenerator(
            ImmutableList.of(depsFile1, depsFile2),
            ImmutableList.of(srcFile1, srcFile2),
            DepsGenerator.InclusionStrategy.ALWAYS,
            "/base/javascript/closure",
            errorManager,
            new ModuleLoader(
                null,
                ImmutableList.of("/base/"),
                ImmutableList.of(),
                BrowserModuleResolver.FACTORY,
                ModuleLoader.PathResolver.ABSOLUTE));
    String output = depsGenerator.computeDependencyCalls();
    assertNoWarnings();
    assertThat(output).isEqualTo(expected);
    depsGenerator =
        new DepsGenerator(
            ImmutableList.<SourceFile>of(),
            ImmutableList.of(depsFile1, depsFile2, srcFile1, srcFile2),
            DepsGenerator.InclusionStrategy.ALWAYS,
            "/base/javascript/closure",
            errorManager,
            new ModuleLoader(
                null,
                ImmutableList.of("/base/"),
                ImmutableList.of(),
                BrowserModuleResolver.FACTORY,
                ModuleLoader.PathResolver.ABSOLUTE));
    String expectedWithDepsAsSources =
        LINE_JOINER.join(
            "goog.addDependency('../../my-project/deps1.js', [], []);",
            "goog.addDependency('../../my-project/deps2.js', [], []);",
            expected);
    output = depsGenerator.computeDependencyCalls();
    assertNoWarnings();
    assertThat(output).isEqualTo(expectedWithDepsAsSources);
  }
@ Test public void testWithDepsAndSources ( ) throws Exception { final SourceFile depsFile1 = SourceFile . fromCode ( "/base/my-project/deps1.js" , LINE_JOINER . join ( "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);" , "goog.addDependency('../prescanned1/file2.js', [], []);" , "goog.addDependency('../this/is/defined/thrice.js', [], []);" , "goog.addDependency('../this/is/defined/thrice.js', [], []);" , "" ) ) ; final SourceFile depsFile2 = SourceFile . fromCode ( "/base/my-project/deps2.js" , LINE_JOINER . join ( "goog.addDependency(" + "'../prescanned2/file1.js'," + " ['dep.bool', 'dep.number']," + " ['dep.string']);" , "goog.addDependency('../prescanned2/file2.js', [], []);" , "goog.addDependency('../this/is/defined/thrice.js', [], []);" , "" ) ) ; final SourceFile srcFile1 = SourceFile . fromCode ( "/base/my-project/src1.js" , LINE_JOINER . join ( "goog.provide('makejsdeps.file1');" , "goog.provide('makejsdeps.file1.Test');" , "" , "/*" , "goog.require('failure1)" , "*/" , "// goog.require('failure2)" , "" , "goog.require('makejsdeps.file2');" , "goog.require(\"goog\");" , "goog.require(\"dep.string\");" , "goog.require(\"dep.number\");" , "" ) ) ; final SourceFile srcFile2 = SourceFile . fromCode ( "/base/my-project/src2.js" , "goog.provide('makejsdeps.file2');" ) ; String expected = LINE_JOINER . join ( "goog.addDependency(" + "'../../my-project/src1.js'," + " ['makejsdeps.file1', 'makejsdeps.file1.Test']," + " ['makejsdeps.file2', 'dep.string', 'dep.number']);" , "goog.addDependency('../../my-project/src2.js', ['makejsdeps.file2'], []);" , "" , "// Included from: /base/my-project/deps1.js" , "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);" , "goog.addDependency('../prescanned1/file2.js', [], []);" , "" , "// Included from: /base/my-project/deps2.js" , "goog.addDependency('../this/is/defined/thrice.js', [], []);" , "goog.addDependency(" + "'../prescanned2/file1.js'," + " ['dep.bool', 'dep.number']," + " ['dep.string']);" , "goog.addDependency('../prescanned2/file2.js', [], []);" , "" ) ; DepsGenerator depsGenerator = new DepsGenerator ( ImmutableList . of ( depsFile1 , depsFile2 ) , ImmutableList . of ( srcFile1 , srcFile2 ) , DepsGenerator . InclusionStrategy . ALWAYS , "/base/javascript/closure" , errorManager , new ModuleLoader ( null , ImmutableList . of ( "/base/" ) , ImmutableList . of ( ) , BrowserModuleResolver . FACTORY , ModuleLoader . PathResolver . ABSOLUTE ) ) ; String output = depsGenerator . computeDependencyCalls ( ) ; assertNoWarnings ( ) ; assertThat ( output ) . isEqualTo ( expected ) ; depsGenerator = new DepsGenerator ( ImmutableList . < SourceFile > of ( ) , ImmutableList . of ( depsFile1 , depsFile2 , srcFile1 , srcFile2 ) , DepsGenerator . InclusionStrategy . ALWAYS , "/base/javascript/closure" , errorManager , new ModuleLoader ( null , ImmutableList . of ( "/base/" ) , ImmutableList . of ( ) , BrowserModuleResolver . FACTORY , ModuleLoader . PathResolver . ABSOLUTE ) ) ; String expectedWithDepsAsSources = LINE_JOINER . join ( "goog.addDependency('../../my-project/deps1.js', [], []);" , "goog.addDependency('../../my-project/deps2.js', [], []);" , expected ) ; output = depsGenerator . computeDependencyCalls ( ) ; assertNoWarnings ( ) ; assertThat ( output ) . isEqualTo ( expectedWithDepsAsSources ) ; }
Ensures that deps files are handled correctly both when listed as deps and when listed as
 sources.
Ensures that deps files are handled correctly both when listed as deps and when listed as sources .
// Test that this appears only once in the output. // Ensure comments are stripped. These cause syntax errors if not stripped. // 'goog' should be silently dropped. // Repeat the test with the deps files listed as sources. // The only difference should be the addition of addDependency() calls for the deps files.