From 9f2a855be500f6a3bc11f1129600b07265a91f7e Mon Sep 17 00:00:00 2001 From: shreyax Date: Mon, 29 Jan 2018 07:32:40 -0800 Subject: Remove hard coded prelude names from some unit tests. PiperOrigin-RevId: 183662908 --- .../build/lib/skyframe/ASTFileLookupFunctionTest.java | 18 ++++++++---------- .../lib/skyframe/SkylarkImportLookupFunctionTest.java | 8 ++++++-- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib/skyframe') diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java index 68437dbdb3..5395b90a8c 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunctionTest.java @@ -23,7 +23,6 @@ import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; import com.google.devtools.build.lib.syntax.SkylarkImport; -import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; @@ -42,16 +41,13 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ASTFileLookupFunctionTest extends BuildViewTestCase { - private static class MockFileSystem extends InMemoryFileSystem { - + private class MockFileSystem extends InMemoryFileSystem { boolean statThrowsIoException; @Override public FileStatus stat(Path path, boolean followSymlinks) throws IOException { if (statThrowsIoException - && path.asFragment() - .getPathString() - .equals("/workspace/tools/build_rules/prelude_" + TestConstants.PRODUCT_NAME)) { + && path.asFragment().getPathString().equals("/workspace/" + preludeLabelRelativePath)) { throw new IOException("bork"); } return super.stat(path, followSymlinks); @@ -59,6 +55,8 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { } private MockFileSystem mockFS; + String preludeLabelRelativePath = + getRuleClassProvider().getPreludeLabel().toPathFragment().toString(); @Override protected FileSystem createFileSystem() { @@ -66,12 +64,12 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { return mockFS; } - @Test + @Test public void testPreludeASTFileIsNotMandatory() throws Exception { reporter.removeHandler(failFastHandler); scratch.file( "foo/BUILD", "genrule(name = 'foo',", " outs = ['out.txt'],", " cmd = 'echo hello >@')"); - scratch.deleteFile("tools/build_rules/prelude_blaze"); + scratch.deleteFile(preludeLabelRelativePath); invalidatePackages(); SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo")); @@ -105,7 +103,7 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { @Test public void testLoadFromBuildFileInRemoteRepo() throws Exception { - scratch.deleteFile("tools/build_rules/prelude_blaze"); + scratch.deleteFile(preludeLabelRelativePath); scratch.overwriteFile("WORKSPACE", "local_repository(", " name = 'a_remote_repo',", @@ -130,7 +128,7 @@ public class ASTFileLookupFunctionTest extends BuildViewTestCase { @Test public void testLoadFromSkylarkFileInRemoteRepo() throws Exception { - scratch.deleteFile("tools/build_rules/prelude_blaze"); + scratch.deleteFile(preludeLabelRelativePath); scratch.overwriteFile("WORKSPACE", "local_repository(", " name = 'a_remote_repo',", diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java index 03ec708273..cee3c4cebc 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java @@ -45,6 +45,8 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { + String preludeLabelRelativePath; + @Before public final void preparePackageLoading() throws Exception { Path alternativeRoot = scratch.dir("/root_2"); @@ -65,6 +67,8 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { ImmutableMap.of(), ImmutableMap.of(), new TimestampGranularityMonitor(BlazeClock.instance())); + this.preludeLabelRelativePath = + getRuleClassProvider().getPreludeLabel().toPathFragment().toString(); } @Test @@ -99,7 +103,7 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { @Test public void testLoadFromSkylarkFileInRemoteRepo() throws Exception { - scratch.deleteFile("tools/build_rules/prelude_blaze"); + scratch.deleteFile(preludeLabelRelativePath); scratch.overwriteFile("WORKSPACE", "local_repository(", " name = 'a_remote_repo',", @@ -238,7 +242,7 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { @Test public void testLoadFromExternalRepoInWorkspaceFileAllowed() throws Exception { - scratch.deleteFile("tools/build_rules/prelude_blaze"); + scratch.deleteFile(preludeLabelRelativePath); scratch.overwriteFile("WORKSPACE", "local_repository(", " name = 'a_remote_repo',", -- cgit v1.2.3