Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Disambiguate .t files instead of directly assuming Perl #20

Closed
wants to merge 1 commit into from

3 participants

Robin Stocker Abhay Mujumdar psybers
Robin Stocker

This is the reason Mercurial is wrongly classified as "mostly Perl" on
Ohloh[1]. It uses ".t" files for test cases, which are wrapped shell
scripts and not Perl.

It would be even better if Ohcount would detect them as shell scripts,
but that seems hard given that the contents (see e.g. [2]) don't have
many defining characteristics.

[1] https://www.ohloh.net/p/mercurial/analyses/latest/languages_summary
[2] http://selenic.com/hg/file/ccd28eca37f6/tests/test-add.t

Robin Stocker Disambiguate .t files instead of directly assuming Perl
This is the reason Mercurial is wrongly classified as "mostly Perl" on
Ohloh[1]. It uses ".t" files for test cases, which are wrapped shell
scripts and not Perl.

It would be even better if Ohcount would detect them as shell scripts,
but that seems hard given that the contents (see e.g. [2]) don't have
many defining characteristics.

[1] https://www.ohloh.net/p/mercurial/analyses/latest/languages_summary
[2] http://selenic.com/hg/file/ccd28eca37f6/tests/test-add.t
6be21cf
Abhay Mujumdar

@robinst thanks! would it be possible for you to add test-cases?

Robin Stocker

Will have to figure out how. I'm getting the following error with ./build, without my commit:

Running detector tests
run_tests: test/unit/detector_test.h:119: test_detector_detect_polyglot: Assertion `lang' failed.
Abhay Mujumdar

Tests are working for me on CentOS 5.5.

psybers

I get a similar test error building on Ubuntu 12.04 on the latest git master:

Running detector tests
run_tests: test/unit/detector_test.h:119: test_detector_detect_polyglot: Assertion `lang' failed.
Aborted (core dumped)

Generating Ruby bindings for i686-linux_ubuntu
ruby/ohcount_wrap.c: In function ‘SWIG_Ruby_define_class’:
ruby/ohcount_wrap.c:1493:9: warning: variable ‘klass’ set but not used [-Wunused-but-set-variable]
Loaded suite ruby_test
Started
............................................................................EE.
Finished in 1.416128 seconds.

1) Error:
test_diff(SourceFileTest):
NoMethodError: undefined method `language' for nil:NilClass
./source_file_test.rb:12:in `test_diff'

2) Error:
test_empty_diff(SourceFileTest):
NoMethodError: undefined method `language' for nil:NilClass
./source_file_test.rb:23:in `test_empty_diff'

79 tests, 156 assertions, 0 failures, 2 errors

Abhay Mujumdar

I asked around about .t files and my colleagues who use Perl disagree that a .t file without a perl-shebang be called non-perl by default. Since what you mention is Mercurial test files, which are checked into tests/ folder, I'd suggest we use Ohloh's ignore-directories feature to suppress that part. Many projects ignore test files and assets using the same method.

Abhay Mujumdar

After ignoring tests/ directory, Mercurial now shows up as mostly written in Python - https://www.ohloh.net/p/mercurial/analyses/latest/languages_summary

Abhay Mujumdar

@psybers what ruby version you have running on Ubuntu 12.04. Ohcount support 1.8.7.

Abhay Mujumdar amujumdar closed this December 13, 2012
Robin Stocker

Ok, this solution is also fine by me. Thanks for taking the time for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 22, 2012
Robin Stocker Disambiguate .t files instead of directly assuming Perl
This is the reason Mercurial is wrongly classified as "mostly Perl" on
Ohloh[1]. It uses ".t" files for test cases, which are wrapped shell
scripts and not Perl.

It would be even better if Ohcount would detect them as shell scripts,
but that seems hard given that the contents (see e.g. [2]) don't have
many defining characteristics.

[1] https://www.ohloh.net/p/mercurial/analyses/latest/languages_summary
[2] http://selenic.com/hg/file/ccd28eca37f6/tests/test-add.t
6be21cf
This page is out of date. Refresh to see the latest.
16  src/detector.c
@@ -901,6 +901,22 @@ const char *disambiguate_st(SourceFile *sourcefile) {
901 901
   return NULL;
902 902
 }
903 903
 
  904
+const char *disambiguate_t(SourceFile *sourcefile) {
  905
+  char *contents = ohcount_sourcefile_get_contents(sourcefile);
  906
+  if (!contents)
  907
+    return NULL;
  908
+
  909
+  // Check for a perl shebang on first line of file
  910
+  const char *error;
  911
+  int erroffset;
  912
+  pcre *re = pcre_compile("#![^\\n]*perl", PCRE_CASELESS, &error, &erroffset, NULL);
  913
+  if (pcre_exec(re, NULL, contents, mystrnlen(contents, 100), 0, PCRE_ANCHORED, NULL, 0) > -1)
  914
+    return LANG_PERL;
  915
+
  916
+  // May be something else, e.g. a test shell script
  917
+  return NULL;
  918
+}
  919
+
904 920
 int ohcount_is_binary_filename(const char *filename) {
905 921
   char *p = (char *)filename + strlen(filename);
906 922
   while (p > filename && *(p - 1) != '.') p--;
2  src/hash/disambiguatefuncs.gperf
@@ -18,6 +18,7 @@ const char *disambiguate_pp(SourceFile *sourcefile);
18 18
 const char *disambiguate_pro(SourceFile *sourcefile);
19 19
 const char *disambiguate_r(SourceFile *sourcefile);
20 20
 const char *disambiguate_st(SourceFile *sourcefile);
  21
+const char *disambiguate_t(SourceFile *sourcefile);
21 22
 %}
22 23
 struct DisambiguateFuncsMap { const char *key; const char* (*value)(SourceFile*); };
23 24
 %%
@@ -37,3 +38,4 @@ pp, disambiguate_pp
37 38
 pro, disambiguate_pro
38 39
 r, disambiguate_r
39 40
 st, disambiguate_st
  41
+t, disambiguate_t
2  src/hash/extensions.gperf
@@ -194,7 +194,7 @@ svg, BINARY
194 194
 svgz, BINARY
195 195
 svn, BINARY
196 196
 swf, BINARY
197  
-t, LANG_PERL
  197
+t, DISAMBIGUATE("t")
198 198
 tar, BINARY
199 199
 tcl, LANG_TCL
200 200
 tex, LANG_TEX
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.