Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"path/filepath"
"regexp"
"strings"
)

const (
Expand All @@ -17,8 +18,12 @@ func isTest(path string) bool {

file := filepath.Base(path)
name := file[:len(file)-len(ext)]
if name == "test" {
if name == "test" || name == "spec" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perl doesn't have test or spec in the name, for what it's worth. Languages that have a different pattern for the test files have this defined in the language config, so we could expose it via the API (and perhaps write it to a dotfile somewhere that we can load and check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea, seems much safer.
On Jan 21, 2016 2:37 PM, "Katrina Owen" notifications@github.com wrote:

In cmd/cmd.go
#273 (comment):

@@ -17,8 +18,12 @@ func isTest(path string) bool {

file := filepath.Base(path)
name := file[:len(file)-len(ext)]
  • if name == "test" {
  • if name == "test" || name == "spec" {

perl doesn't have test or spec in the name, for what it's worth. Languages
that have a different pattern for the test files have this defined in the
language config, so we could expose it via the API (and perhaps write it to
a dotfile somewhere that we can load and check.


Reply to this email directly or view it on GitHub
https://github.com/exercism/cli/pull/273/files#r50451141.

return true
}
return regexp.MustCompile(`[\._-]?[tT]est`).MatchString(name)
return regexp.MustCompile(`[\._-]?([tT]est|[sS]pec)`).MatchString(name)
}

func isREADME(path string) bool {
return strings.Contains(path, "README")
}
42 changes: 42 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestIsTest(t *testing.T) {
name: "problem/Whatever.t", // perl
isTest: true,
},
{
name: "whatever_spec.ext", // lua
isTest: true,
},
}

for _, tt := range testCases {
Expand All @@ -51,3 +55,41 @@ func TestIsTest(t *testing.T) {
}
}
}

func TestIsREADME(t *testing.T) {
testCases := []struct {
name string
isREADME bool
}{
{
name: "problem/README.md",
isREADME: true,
},
{
name: "problem/README",
isREADME: true,
},
{
name: "problem/README.txt",
isREADME: true,
},
{
name: "problem/some_problem.py",
isREADME: false,
},
{
name: "problem/readme.lua",
isREADME: false,
},
{
name: "problem/readme_spec.lua",
isREADME: false,
},
}

for _, tt := range testCases {
if isREADME(tt.name) != tt.isREADME {
t.Fatalf("Expected isREADME(%s) to be %t", tt.name, tt.isREADME)
}
}
}
4 changes: 4 additions & 0 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func Submit(ctx *cli.Context) {
"you want, please pass the --test flag to exercism submit.")
}

if isREADME(filename) {
log.Fatal("You cannot submit the README as a solution.")
}

file, err := filepath.Abs(filename)
if err != nil {
log.Fatal(err)
Expand Down