public static string CreateTempDirectory() { var path = Path.Combine(BazelEnvironment.GetTmpDir(), Path.GetRandomFileName()); Directory.CreateDirectory(path); return(path); }
public void TestDirectoryBasedCtorArgumentValidation() { AssertThrows <ArgumentException>( () => Runfiles.CreateDirectoryBasedForTesting(null)); AssertThrows <ArgumentException>(() => Runfiles.CreateDirectoryBasedForTesting("")); AssertThrows <ArgumentException>( () => Runfiles.CreateDirectoryBasedForTesting("non-existent directory is bad")); Runfiles.CreateDirectoryBasedForTesting(BazelEnvironment.GetTmpDir()); }
public E2eTests(ITestOutputHelper helper) { _helper = helper; _tmp = BazelEnvironment.GetTmpDir(nameof(E2eTests)); string execRoot = Path.Combine(_tmp, "execroot"); Directory.CreateDirectory(execRoot); Directory.SetCurrentDirectory(execRoot); _execRoot = Directory.GetCurrentDirectory(); // in case _execRoot is a symlink (/var => /private/var) _tmp = Path.GetDirectoryName(_execRoot) !; }
public int Run() { var testTmpDir = BazelEnvironment.GetTmpDir(); Info($"Creating test directory with {testTmpDir}"); // assumes we're not in a sandbox i.e. tags = ["local"] var execRootIndex = testTmpDir.IndexOf("/execroot/", StringComparison.OrdinalIgnoreCase); if (execRootIndex < 0) { throw new Exception($"Bad tmpdir: {testTmpDir}"); } var outputBaseDir = testTmpDir[..execRootIndex];
public void TestDirectoryBasedRlocation() { // The DirectoryBased implementation simply joins the runfiles directory and the runfile's path // on a "/". DirectoryBased does not perform any normalization, nor does it check that the path // exists. var dir = Path.Combine(BazelEnvironment.GetTmpDir() !, "mock/runfiles"); Directory.CreateDirectory(dir).Exists.Should().Be(true); var r = Runfiles.CreateDirectoryBasedForTesting(dir); // Escaping for "\": once for string and once for regex. r.Rlocation("arg").Should().MatchRegex(@".*[/\\]mock[/\\]runfiles[/\\]arg"); }
public void WorkspaceInit(string workspaceName) { _testDir = BazelEnvironment.GetTmpDir($"{nameof(WorkspaceInit)}_{workspaceName}"); var specs = CollectSpecs(workspaceName); var templates = new Templates() { Workspace = new Template("WORKSPACE", "FAKE_WORKSPACE"), RootBuild = new Template("BUILD.bazel", "FAKE_ROOT_BUILD"), BazelProps = new Template("Bazel.props", "FAKE_BAZEL_PROPS"), BazelTargets = new Template("Bazel.targets", "FAKE_BAZEL_TARGETS"), DirectoryProps = new Template("Directory.Build.props", "FAKE_DIRECTORY_PROPS"), DirectoryTargets = new Template("Directory.Build.targets", "FAKE_DIRECTORY_TARGETS"), SolutionProps = new Template("Directory.Solution.props", "FAKE_SOLUTION_PROPS"), SolutionTargets = new Template("Directory.Solution.targets", "FAKE_SOLUTION_TARGETS"), }; foreach (var template in templates.XmlMerge) { template.Contents = $"<Project>\n {template.Contents}\n</Project>\n"; } var maker = new WorkspaceMaker(_testDir, workspaceName, templates); maker.Init(); foreach (var spec in specs) { var info = new FileInfo(Path.Combine(_testDir, spec.Rel)); info.Exists.Should().BeTrue($"`{spec.Rel}` should have been created."); var contents = File.ReadAllLines(info.FullName); // var joined = string.Join("\n", contents); // foreach (var regex in spec.Regexes) // { // regex.IsMatch(joined).Should().BeTrue($"`{regex}` should have matched:\n```\n{joined}\n```"); // } if (spec.Contents.Length > 0) { var builder = new StringBuilder().AppendLine(spec.Rel); var expectedIndex = 0; var actualIndex = 0; var actual = contents; var expected = spec.Contents; var failed = false; for (; expectedIndex < expected.Length && actualIndex < actual.Length;) { var e = expected[expectedIndex]; var a = actual[actualIndex]; if (string.CompareOrdinal(e, a) == 0) { builder.Append(" "); builder.AppendLine(e); } else { failed = true; builder.Append(" - "); builder.AppendLine(e); builder.Append(" + "); builder.AppendLine(a); } expectedIndex++; actualIndex++; } failed.Should().Be(false, builder.ToString()); } } }
public static string CreateTempFile() { var testTmpdir = BazelEnvironment.GetTmpDir(); return(Path.Combine(testTmpdir, Path.GetRandomFileName())); }