1 require File.dirname(__FILE__) + '/../test_helper'
3 class Ohcount::LicensesSnifferTest < Ohcount::Test
5 # To make test creation easy & straighforward, we use a
6 # file-based convention, as follows:
8 # test/src_licenses/<license_name>_t1.c <-- a 'C' file
9 # containing <license_name>
11 # test/expected_licences/<license_name>_t1 <-- a text file containg
12 # space-delimited list of
15 # This test loops over every file in the src_licenses directory ensuring
16 # the expected results are achieved.
18 def test_expected_licenses
19 src_dir = File.dirname(__FILE__) + "/../src_licenses"
20 expected_dir = File.dirname(__FILE__) + "/../expected_licenses"
22 Dir.entries(src_dir).each do |f|
23 filename = src_dir + "/" + f
24 next if File.directory?(filename)
25 next if f[0..0] == "."
27 detected_licenses = Ohcount::SourceFile.new(filename).licenses
29 detected_licenses = detected_licenses.sort { |a,b| a.to_s <=> b.to_s }
34 expected_filename = $1
35 expected_licenses = File.new(expected_dir + "/" + expected_filename).read.split.sort.collect { |l| l.intern }
39 assert false, "Missing expected_licenses file for #{ f }"
44 assert_equal expected_licenses, detected_licenses, "Mismatch in file #{ f }"