From ae95db12a1afb4066febd5fefa0008eebea9ff5f Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 17 Feb 2024 11:21:37 +0100 Subject: [PATCH] A new test to exercise `linguist-language=` Rename `repo_lang_stats_test.go` to `linguist_test.go`, and add a new tests that exercises parts of the web UI to ensure that language overrides in `.gitattributes` work when viewing a file source, and in the blame view too. Signed-off-by: Gergely Nagy --- ...po_lang_stats_test.go => linguist_test.go} | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) rename tests/integration/{repo_lang_stats_test.go => linguist_test.go} (87%) diff --git a/tests/integration/repo_lang_stats_test.go b/tests/integration/linguist_test.go similarity index 87% rename from tests/integration/repo_lang_stats_test.go rename to tests/integration/linguist_test.go index 3cc924c81b..12f12f5cb0 100644 --- a/tests/integration/repo_lang_stats_test.go +++ b/tests/integration/linguist_test.go @@ -5,6 +5,7 @@ package integration import ( "context" + "net/http" "net/url" "strings" "testing" @@ -22,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRepoLangStats(t *testing.T) { +func TestLinguistSupport(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { /****************** ** Preparations ** @@ -219,5 +220,36 @@ func TestRepoLangStats(t *testing.T) { langs := getFreshLanguageStats(t, repo, sha) assert.Empty(t, langs) }) + + // 9. Overriding the language + t.Run("linguist-language", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + repo, _, f := prep(t, "foo.c linguist-language=sh\n") + defer f() + + assertFileLanguage := func(t *testing.T, uri, expectedLanguage string) { + t.Helper() + + req := NewRequest(t, "GET", repo.Link()+uri) + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + language := strings.TrimSpace(htmlDoc.Find(".file-info .file-info-entry:nth-child(3)").Text()) + assert.Equal(t, expectedLanguage, language) + } + + t.Run("file source view", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash") + }) + + t.Run("file blame view", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash") + }) + }) }) }