Files
carbon-lang/proposals/scripts/new_proposal_test.py
T
Jon Ross-Perkins 6204a27ea9 Start adapting to bzlmod configurations. (#3505)
Some background information is at https://bazel.build/external/migration

Trying to handle the simple cases first. This adds a requirement for
bazel 7 due to differences in bzlmod handling between 6 and 7 (also
discussed on
[#infra](https://discord.com/channels/655572317891461132/707150492370862090/1184942191412510720)).
Bazel seems to be okay with a partial migration such as ths.

The python import behavior has subtly shifted, so `carbon.` is no longer
part of import paths. There's a version-incompatible change for `@@`.
bzlmod makes repos sometimes show as `name~version`.

`target-determinator` seems to be okay with `@@` after a version update.

Things not moved here are things that basically need more dep work:

- clang_register_toolchains because I need to dive into its format.
- llvm-project because we need something slightly atypical, I need to
make sure patching and the repo work carries over.
- com_google_libprotobuf_mutator is sufficiently atypical that it
doesn't have a module already, but should be one of the easier things to
fix.
- brotli/woff2: I think we should actually consider removing these. But
again, they're not trivial moves.
- treesitter due to toolchain registration, which has shifted a bit.
- rules_nodejs because treesitter depends on it in an awkward way to
migrate.
2023-12-15 01:05:35 +00:00

66 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Tests for new_proposal.py."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import os
import unittest
from proposals.scripts import new_proposal
class TestNewProposal(unittest.TestCase):
def test_calculate_branch_short(self):
parsed_args = new_proposal._parse_args(["foo bar"])
self.assertEqual(
new_proposal._calculate_branch(parsed_args), "proposal-foo-bar"
)
def test_calculate_branch_long(self):
parsed_args = new_proposal._parse_args(
["A really long long long title"]
)
self.assertEqual(
new_proposal._calculate_branch(parsed_args),
"proposal-a-really-long-long-l",
)
def test_calculate_branch_flag(self):
parsed_args = new_proposal._parse_args(["--branch=wiz", "foo"])
self.assertEqual(new_proposal._calculate_branch(parsed_args), "wiz")
def test_fill_template(self):
parsed_args = new_proposal._parse_args(["foo"])
content = new_proposal._fill_template(
os.path.join(
new_proposal._get_proposals_dir(parsed_args),
"scripts/template.md",
),
"TITLE",
123,
)
self.assertTrue(content.startswith("# TITLE\n\n"), content)
self.assertTrue(
"[Pull request](https://github.com/carbon-language/carbon-lang/"
"pull/123)" in content,
content,
)
self.assertTrue(
"<!-- tocstop -->\n\n## Abstract\n\n" in content, content
)
def test_run_success(self):
new_proposal._run(["true"])
def test_run_failure(self):
self.assertRaises(SystemExit, new_proposal._run, ["false"])
if __name__ == "__main__":
unittest.main()