Skip to content

Testing with examples from https://en.cppreference.com/w/ #314

Open
@mingodad

Description

@mingodad

Using the Lua script shown bellow to extract the code examples from https://en.cppreference.com/w/ I'm getting this results:

#cxx
Total files scanned     :	5629
Total files with code   :	2889
Total files failed code :	172

#clang-17
Total files scanned     :	5629
Total files with code   :	2889
Total files failed code :	266

#g++-13
Total files scanned     :	5629
Total files with code   :	2889
Total files failed code :	197

#circle-200
Total files scanned     :	5629
Total files with code   :	2889
Total files failed code :	474
local base_dir = "/home/mingo/.local/share/Zeal/Zeal/docsets/C++.docset/Contents/Resources/Documents/en.cppreference.com/w/cpp/";

local cppCodeFName = "/tmp/cppCode.cpp";
--local cxx_cmd = "../build/src/frontend/cxx -fsyntax-only -toolchain linux " .. cppCodeFName;
--local cxx_cmd = "/usr/bin/time ../build-release/src/frontend/cxx -fsyntax-only -toolchain linux " .. cppCodeFName;
local cxx_cmd = "/usr/bin/time ./cxx -fsyntax-only -toolchain linux " .. cppCodeFName;
--local cxx_cmd = "clang-17-env /usr/bin/time clang++ -std=c++23 -fsyntax-only " .. cppCodeFName;
--local cxx_cmd = "clang-17-env /usr/bin/time clang++ -fsyntax-only " .. cppCodeFName;
--local cxx_cmd = "gcc-13-env /usr/bin/time g++ -std=c++23 -fsyntax-only " .. cppCodeFName;
--local cxx_cmd = "gcc-13-env /usr/bin/time g++ -fsyntax-only " .. cppCodeFName;
--local cxx_cmd = "/usr/bin/time timeout 3s circle  -std=c++2b -fsyntax-only " .. cppCodeFName;

local code_re = "<div class=\"t%-example%-live%-link\">.-<div class=\"cpp source%-cpp\">(.-)</pre></div>";

local find_cmd = "find " .. base_dir .. " -name '*.html'";
local start_t = os.time();

local html_list = {};
for fname in io.popen(find_cmd, "r"):lines("l") do
	table.insert(html_list, fname);
end
table.sort(html_list);

local count_with_code = 0;
local fname_with_code_failed = {};
for idx, fname in ipairs(html_list) do
	print(fname);

	local html = io.open(fname, "r"):read("a");
	for code in html:gmatch(code_re) do
		code = code:gsub("%b<>", "");
		code = code:gsub("&nbsp;", " ");
		code = code:gsub("&lt;", "<");
		code = code:gsub("&gt;", ">");
		code = code:gsub("&amp;", "&");

		--print("//====Start");
		--print(code);
		--print("//====End");

		local fd = io.open(cppCodeFName, "w");
		fd:write(code);
		fd:close();
		count_with_code = count_with_code + 1;
		print("==CHECK==")
		print(cxx_cmd);
		io.stdout:flush();
		local rc, rc_type, rc_code = os.execute(cxx_cmd);
		if rc_code == 0 then
			print("==rc:OK==")
		else
			table.insert(fname_with_code_failed, idx);
			print("==rc:FAILED==")
			print("//====Start");
			print(code);
			print("//====End");
		end
	end

end
local end_t = os.time();
print("elapsed time: ", os.difftime(end_t, start_t));
print("Total files scanned     :", #html_list);
print("Total files with code   :", count_with_code);
print("Total files failed code :", #fname_with_code_failed);
for idx, fname_idx in ipairs(fname_with_code_failed) do
	print(html_list[fname_idx]);
end

See attached the output for cxx and clang-17:
test-cpp-reference-examples-cxx.output.zip
test-cpp-reference-examples-clang-17-std23.output.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions